SurrealDB is open-source NewSQL database released in july 2022. It is suitable for any type of application and has many features.
- Data change events
- Permissions
- Schemafull
- Scemaless
- Relaional
- Temporal
- Full-Text search
- Scalable
- Serverless
- Embeded
- Realtime
- Graph
- Multi-tenant
- Acid
SurrealDB is built with Rust language and was created by Tobie Morgan Hitchcock and Jaime Morgan Hitchcock. It uses its own SQL like language named SurrealQL. By default it is scemaless but can be scemafull. In SurrealDB its really easy to create links between tables and it has event system that trigers when data is changed.
Windows PowerShell
iwr https://windows.surrealdb.com -useb | iex
choco install surreal --pre
Linux
curl -sSf https://install.surrealdb.com | sh
MacOS
brew install surrealdb/tap/surreal
Docker
docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start
You can use SurrealDB in console or use one libraries.
I am going to use RestAPI and VSCode Thunder client extention.
surreal start --log debug --user root --pass root memory
NS = text - it sets namespace
DB = text - it sets DB name
Username = root
Password = root
Setup is done, now we can write our commands in Body tab
Every record in SurrealDB has UniqueID that consists of table name on the right and id on the left of semicolumn. UniqueID can be defined by user: table:id
or be random: table:{random}
.
Let's create some humans
CREATE:
CREATE human:brian SET name="Brian", age=24;
CREATE human:john SET name="John", age=30;
CREATE human:Kevin SET name="Kevin", age=59;
Now let's print all our humans
SELECT
SELECT * FROM human;
Next we will add skills to all our humans UPDATE
UPDATE human SET skills += ['breathing', 'walking'];
And let's add best friend to Kevin
UPDATE human:kevin SET best_friend = human:brian;
In SurrealDB we can easily print properties of relations SELECT
SELECT best_friend.name, best_friend.skills FROM human:kevin;
As well as one-to-one relations SurrealDB supports one-to-many relations
CREATE job:developer SET salary=5000;
CREATE job:designer SET salary=3500;
UPDATE human:brian SET jobs = ['job:developer', 'job:designer'];
Now we can easily get all salaries of kevins best friend
SELECT best_friend.jobs.salary FROM human:kevin;
That were some thing that SurrealDB can do. But there is much more. For example events, permissions and more.
Here are some resources: