DEV Community

Cover image for SurrealDB: Version 1.0 Just Released! Next Gen SQL Database?
Sebastian Fritsch
Sebastian Fritsch

Posted on

SurrealDB: Version 1.0 Just Released! Next Gen SQL Database?

SurrealDB: Version 1.0 Just Released! Next Gen SQL Database?

Introducing the Future of Database Management: Version 1.0 Just Released! πŸš€ Is this the Next Gen SQL Database You've Been Waiting For? 🌟

Explaining why SurrealDB through historical context

First, let's delve into why SurrealDB stands out in contrast to widely-used databases.

From physical paper to digital paper

  • Relational (Table): SQL
  • Document: NoSQL
  • Graph

Relational databases πŸ“Š

SQL is like a puzzle. You plan, create, and assemble pieces to get your answer, often requiring multiple pieces for each solution.

price_list

id price
1 1.7
2 1.5
3 22.99

fruit_box

id fruit quantity
1 Apple 5
2 Orange 3
3 Durian 1000
select * from fruit_box

select fruit from fruit_box

select fruit, price from fruit_box fb

inner join price_list pl on fb.id=pl.id
Enter fullscreen mode Exit fullscreen mode
  • The first query retrieves all data from the fruit_box table.
  • The second query retrieves only the fruit column from the fruit_box table.
  • The third query combines data from both the fruit_box _and price_list_ tables, showing the fruit names and their associated prices where there is a matching id in both tables.

SQL is like a puzzle. You plan, create, and assemble pieces to get your answer, often requiring multiple pieces for each solution.

Document πŸ“„

I prefer a straightforward approach. Instead of solving a puzzle each time, I'd rather create a comprehensive document with all the needed information. Then, I can simply read that document to find the answers I seek.

db={
    "fruit_box": [
        {
            "_id": 1,
            "fruit": "Apple",
            "quantity": 5
        },
        {
            "_id": 2,
            "fruit": "Orange",
            "quantity": 3
        },
        {
            "_id": 3,
            "fruit": "Durian",
            "quantity": 1000
        },
    ]
}
Enter fullscreen mode Exit fullscreen mode
"price_list": [
    {
        "_id": 1,
        "price": 1.7,
    },
    {
        "_id": 2,
        "price": 1.5,
    },
    {
        "_id": 3,
        "price": 22.99,
    },
]
Enter fullscreen mode Exit fullscreen mode
db.fruit_box.find()

db.fruit_box.find({}, {fruit: 1, _id: 0})

db.fruit_box.aggregate([{
    "$lookup": {
        "from": "price_list",
        "localField": "_id",
        "foreignField": "_id",
        "as": "Result"
    }
}])


Enter fullscreen mode Exit fullscreen mode

Graph πŸ•ΈοΈ

Similar to a social network, you map out who knows what and how they're connected. Then, you navigate through the network, asking until you find what you need.

(1:fruit_box {fruit:"Apple",quantity:5})

(2:fruit_box {fruit:"Orange",quantity:3})

(3:fruit_box {fruit:"Durian",quantity:1000})

(1:price_list {price:1.7})

(2:price_list {price:1.5})

(3:price_list {price:22.99})
Enter fullscreen mode Exit fullscreen mode
match (f:fruit_box)

return f

match (f:fruit_box)

return f.fruit

match (f:fruit_box)-[:lookup]->(p:price_list)

return f.fruit, p.price
Enter fullscreen mode Exit fullscreen mode

NewSQL - SurrealQL

select fruit,

->lookup->price_list.price as price

from fruit_box
Enter fullscreen mode Exit fullscreen mode

SurrealQL simplifies the complexity, particularly regarding table relationships. Additionally, if you insert data into a non-existent table, SurrealDB will generate the table automatically.

Nice Features and small size

SurrealDB offers a wealth of features, and its version 1.0.0 Docker image is exceptionally compact at just 17.5 MB, thanks to its Rust-based architecture. In comparison, Postgresql's image size exceeds 80 MB.

When using SurrealDB within a web browser, the WebAssembly library provides support for connecting to a remote database via HTTP or WebSockets. It also allows for data persistence using IndexedDB in the browser. You have the flexibility to choose between a schemafull or schemaless approach. You can store unstructured nested data with any columns or selectively limit data storage to specific columns or fields. This means you can start quickly without the need to define every column and transition to a schema-full approach once your data model is established.

Oh and did I mention in SurrealQL, comments can be written in a number of different ways.

/* In SurrealQL, comments can be written as single-line or multi-line comments,

and comments can be used and interspersed within statements. */

SELECT  FROM / get all users */ user;

There are a number of ways to use single-line comments
SELECT * FROM user;

// Alternatively using two forward-slash characters

SELECT * FROM user;

-- Another way is to use two dash characters

SELECT * FROM user;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)