SurrealDB - an extraordinary database presented in 100 seconds (video)
Fireship recently published a video about SurrealDB, a modern, open-source SQL database that offers many features every developer dreams of. It was initiated by Jamie and Toby Morgan Hitchcock in 2015 and open-sourced in July 2022. SurrealDB is a highly versatile database that employs various paradigms such as relational, graph, and document to deliver simplicity via an SQL-like query language. This multi-model database boasts capabilities for handling real-time data, featuring graphs, and supporting geospatial data, all while maintaining ACID compliance. SurrealDB excels in managing complex relationships within data, making it stand out in the database market.
One of the key advantages of SurrealDB is its flexibility, as it is schema-less by default, allowing for freeform data creation in any table. However, transitioning to schema-full tables is possible when the data model becomes more defined. With support for transactional conditions and real-time updates, developers can easily listen for events from front-end applications, much like Firebase. Furthermore, SurrealDB provides built-in analytic functions and the ability to restrict access to data.
In the video, Fireship showcases how easy it is to start working with SurrealDB. The first step is to install the database on your machine and run it locally with the CLI. Using straightforward SQL commands like CREATE, developers can add records to the database. It's crucial that every record has a unique ID comprised of two parts, which creates additional flexibility in data management. Developers can also use the SET command to define the data for a specific record or CONTENT for a more complex JSON-like syntax.
As for querying capabilities, SurrealDB makes things even more interesting. Developers can use classic SELECT queries with a WHERE clause, and they also have access to built-in functions like COUNT for data aggregation. SurrealDB also allows embedding your own JavaScript logic directly into queries, significantly enhancing flexibility. Without utilizing foreign keys, unique record IDs can be stored in other records, allowing for easy querying using dot notation.
In conclusion, Fireship emphasizes that the video is only 100 seconds long, which is quite remarkable considering the range of features and capabilities that SurrealDB provides. At the time of writing this article, the video has achieved 435905 views and 22666 likes, highlighting its popularity among developers. If you wish to delve deeper into the topic, Fireship invites you to check out the new channel Beyond Fireship, where more content related to SurrealDB will be shared.
Toggle timeline summary
-
Introduction to SurrealDB, a new open-source SQL database.
-
Key features include ACID compliance, scalability, and various data models.
-
SurrealDB combines relational, graph, and document paradigms.
-
It uses an SQL-like language for queries.
-
Started by Jamie and Toby Morgan Hitchcock in 2015, open-sourced in July 2022.
-
Built in Rust, supports multiple persistence layers.
-
Handles complex relationships without traditional joins.
-
Schema-less by default, but supports schema-full tables.
-
ACID-compliant transactions across multiple tables.
-
Real-time updates, similar to Firebase.
-
Features include geospatial data and permissions management.
-
Installation and usage of SurrealDB via CLI and REST API.
-
Creating new records using SQL statements.
-
Querying data using SELECT statements and WHERE clauses.
-
Embedding JavaScript logic directly into queries.
-
Using record IDs for relationships instead of foreign keys.
-
Graph edges can be added between records for efficient querying.
-
Conclusion and invitation to explore beyond SurrealDB.
Transcription
SurrealDB, an open-source, new SQL database that delivers every feature you've ever dreamed of. ACID, Scalable, Full-text Search, Real-time, Graph, Relational, Multi-tenant, Temporal, Schema-less, Schema-full, Server-less, Embedded, are all words that can describe SurrealDB, a multi-model database that combines elements of relational, graph, and document paradigms into a simple package that can be queried with an SQL-like language. Development was started by Jamie and Toby Morgan Hitchcock in 2015, and it was open-sourced in July 2022. The engine is written in Rust, and can support multiple persistence layers, like TyKB to scale horizontally in the cloud, or as a single node, both in memory or on disk. Most importantly though, it can handle complex relationships like traditional relational databases, but does so without joins. Instead, it uses techniques like record links and graph connections that not only handle complex data models, but also result in concise, developer-friendly code. By default, it's schema-less, which means you can implicitly create unstructured data in any table. However, you can opt into schema-full tables when the data model becomes well-defined. It's also ACID-compliant, allowing you to run transactions across multiple tables, which also emit events when the data changes, so you can listen to real-time updates from a front-end application, kind of like Firebase. And the feature list goes on with things like geospatial data and predefined analytics views, all of which can be locked down with permissions out of the box. To get started, install it on your machine, then run it locally with the CLI, then execute code using its REST API or a client library for your favorite language. Just like SQL, we can use statements like CREATE to add a record to the database. Every record has a unique ID comprised of two parts. The left side is the table the record belongs to, and the right side can be whatever you want, or if left out, it will be automatically generated. And now use SET to define the data for that record. Or try CONTENT for a more JSON-like syntax. Now that we have some data populated, we can query it with a SELECT statement. It supports the WHERE clause to filter by a condition, and has a variety of built-in functions like COUNT to fetch aggregate data, or IS to validate common data formats like an email. And if that's not enough, you can even embed your own JavaScript logic directly into a query. But remember, there are no joins in the Surreal Life. Instead of foreign keys, record IDs can be stored in any other record. That makes it possible to query that data using a simple SELECT statement that uses dot notation to specify the fields that should be joined in. That takes care of most relationships, but you can even add graph edges between records using the RELATE statement. You can now query this data efficiently using arrows to traverse between nodes and edges. This has been SurrealDB in 100 seconds. If you want to go beyond 100 seconds, check out my new channel, Beyond Fireship, where I'll be taking you on an extended Surreal journey. Thanks for watching, and I will see you in the next one.