With an SQL-style query language, real-time queries with highly-efficient related data retrieval, advanced security permissions for multi-tenant access, and support for performant analytical workloads, SurrealDB is the next generation serverless database.
SurrealDB is an innovative NewSQL cloud database, suitable for serverless applications, jamstack applications, single-page applications, and traditional applications. It is unmatched in its versatility and financial value, with the ability for deployment on cloud, on-premise, embedded, and edge computing environments. For a hassle-free setup, get started with SurrealDB Cloud in one-click.
There is no need for your team to learn new complicated database languages. Getting started with SurrealDB is as simple as one command - and advanced functionality is simple to understand, whilst still being fast and performant.
SurrealDB simplifies your database and API stack, removing the need for most server-side components. As a web database, client-side applications can be built with direct connections to SurrealDB, while traditional server-side development techniques can still leverage the powerful but simple querying and analytics abilities.
Forget about scaling databases, servers, loadbalancers, and API endpoints. SurrealDB takes the hassle out of your stack, enabling you to grow and operate at scale with a highly-available, highly-scalable distributed platform. Deploy anywhere, or keep it simple with SurrealDB Cloud.
SurrealDB is a flexible, developer-friendly, fully ACID transactional, realtime document-graph web database for serverless applications. Never again worry about database provisioning, scaling, sharding, replication, or correctness.
Document & graph database
JOIN-less deep fetching
Distributed ACID transactions
Built with Rust
Structured and un-structured data
GraphQL and REST API
Support for multi-tenant apps
Multi-row, multi-table transactions
Online and offline data sync
In-built access and permissions
Multi-column and full-text indexes
Incrementally computed views
Distributed and highly-scalable
No complex back-end servers and APIs
SurrealDB doesn't force you into setting up your data model in any one way. Instead you can choose between simple documents, documents with embedded fields, or related graph connections between records. Use schemafull or schemaless tables giving you the flexibility to store whatever you need.
Once stored in SurrealDB, all data is strongly typed, with the ability to convert between different types seamlessly - and numbers can be stored and computed with 64 bit precision or as arbritrary length decimals.
-- Create a 'user' record CREATE user SET age = <int> 34, enabled = true, -- Store the current time created_at = time::now(), -- Specify embedded fields name.first = "Tobie", name.last = "Morgan Hitchcock", -- Add a field which is computed from other fields name.full = <string> string::join(' ', name.first, name.last), -- Add an array whose values point to other remote records friends = [user:gna732gnajan74hj, user:gna732gnajan74hj], ;
-- Select all users and fetch the users' friends' names SELECT *, friends.*.name.full AS friends FROM user; -- Set a variable to be used in subsequent statements LET $tobie = (SELECT * FROM user WHERE name.first = "Tobie"); -- Select all users with complex graph traversal SELECT *, -- Select all users who like this user <-like<-user AS friends, -- Select all products which friends have purchased <-like<-user->purchase->product AS recommended -- Only look at the single user selected above FROM $tobie ;
The primary method of querying SurrealDB is using SurrealQL, a similar but modified version of traditional SQL. SurrealQL enables linked documents to be traversed and queried efficiently, while still using an imperative language which remains understandable by data scientists.
With an innovative, but simple-to-understand, SQL language developers or data scientists can use a myriad of different techniques to store, query, and analyse the data in SurrealDB.
SurrealDB is designed to be quick to setup, and even quicker to implement. Multi-column indexes can be easily added and removed as your application evolves, allowing for strongly consistent reads and writes, and highly-performant reads.
Pre-computed table views allow superfast and highly-efficient aggregated data for queries which are known upfront - with simple view definition as easy as writing an SQL statement.
-- Add a new 'user' record with some basic attributes CREATE user SET age = 34, gender = 'm', name = 'Tobie Morgan Hitchcock' ; -- Define a table which aggregates data from another table DEFINE TABLE users_by_gender AS SELECT gender, count() AS total, math::mean(age) AS average_age FROM user GROUP BY gender ;
-- Specify access permissions for the 'post' table DEFINE TABLE post SCHEMALESS PERMISSIONS FOR select -- Published posts can be selected WHERE published = true -- A user can select all their own posts OR user = $auth.id FOR create, update -- A user can create or update their own posts WHERE user = $auth.id FOR delete -- A user can delete their own posts WHERE user = $auth.id -- Or an admin can delete any posts OR $auth.admin = true ;
WIth permissions in-built from the ground up, SurrealDB is the perfect web-database for serverless applications. Easily specify permissions with easy-to-write SQL statements, ensuring that only the correct users can access the specified data that they have permission to select or modify.
With support for SSL/TLS, Single-Sign-On, external 3rd party authentication, JWT token based authentication, and custom business authentication logic - SurrealDB offers strong security, with the flexibility of custom authentication methods that suit your app or business.
When connecting with SurrealDB, all connections are made using WebSockets, allowing for bi-directional data syncing. Dependent on data access permissions, client-based document subscriptions are triggered in real-time whenever changes are made to the data.
Data subscriptions can be specified for whole tables, filtered result sets, or individual records - enabling a multitude of different use-cases in all types of applications.
-- Subscribe to all changes to documents which match LIVE SELECT * FROM document WHERE account = $auth.account OR public = true ; -- Subscribe to all changes to a single 'post' record LIVE SELECT * FROM post:c569rth77ad48tc6s3ig; -- Stop receiving change notifications KILL "1986cc4e-340a-467d-9290-de81583267a2";
import * as surreal from "https://deno.land/x/surrealdb/mod.ts";
SurrealDB is being built in the open. We would love for you to be involved.