surrealdb-nightly

Crates.iosurrealdb-nightly
lib.rssurrealdb-nightly
version2.0.20240711
sourcesrc
created_at2023-11-20 12:30:30.695468
updated_at2024-07-16 00:45:37.674925
descriptionA nightly release of the surrealdb crate
homepagehttps://github.com/surrealdb/surrealdb
repositoryhttps://github.com/surrealdb/surrealdb
max_upload_size
id1042054
size1,350,253
Tobie Morgan Hitchcock (tobiemh)

documentation

https://docs.rs/surrealdb/

README


SurrealDB Logo

SurrealDB is the ultimate cloud
database for tomorrow's applications

Develop easier.   Build faster.   Scale quicker.


A scalable, distributed, collaborative, document-graph database, for the realtime web.


     

Blog   Github	  LinkedIn   Twitter   Youtube   Dev   Discord   StackOverflow


  What is SurrealDB?

SurrealDB is an end-to-end cloud native database for web, mobile, serverless, jamstack, backend, and traditional applications. SurrealDB reduces the development time of modern applications by simplifying your database and API stack, removing the need for most server-side components, allowing you to build secure, performant apps quicker and cheaper. SurrealDB acts as both a database and a modern, realtime, collaborative API backend layer. SurrealDB can run as a single server or in a highly-available, highly-scalable distributed mode - with support for SQL querying from client devices, GraphQL, ACID transactions, WebSocket connections, structured and unstructured data, graph querying, full-text indexing, geospatial querying, and row-by-row permissions-based access.

View the features, the latest releases, the product roadmap, and documentation.

  Features

  • Database server, or embedded library
  • Multi-row, multi-table ACID transactions
  • Single-node, or highly-scalable distributed mode
  • Record links and directed typed graph connections
  • Store structured and unstructured data
  • Incrementally computed views for pre-computed advanced analytics
  • Realtime-api layer, and security permissions built in
  • Store and model data in any way with tables, documents, and graph
  • Simple schema definition for frontend and backend development
  • Connect and query directly from web-browsers and client devices
  • Use embedded JavaScript functions for custom advanced functionality

  Documentation

For guidance on installation, development, deployment, and administration, see our documentation.

  Installation

SurrealDB is designed to be simple to install and simple to run - using just one command from your terminal. In addition to traditional installation, SurrealDB can be installed and run with HomeBrew, Docker, or using any other container orchestration tool such as Docker Compose, Docker Swarm, Rancher, or in Kubernetes.

  Install on macOS

The quickest way to get going with SurrealDB on macOS is to use Homebrew. This will install both the command-line tools, and the SurrealDB server as a single executable. If you don't use Homebrew, follow the instructions for Linux below to install SurrealDB.

brew install surrealdb/tap/surreal

  Install on Linux

The easiest and preferred way to get going with SurrealDB on Unix operating systems is to install and use the SurrealDB command-line tool. Run the following command in your terminal and follow the on-screen instructions.

curl -sSf https://install.surrealdb.com | sh

  Install on Windows

The easiest and preferred way to get going with SurrealDB on Windows is to install and use the SurrealDB command-line tool. Run the following command in your terminal and follow the on-screen instructions.

iwr https://install.surrealdb.com -useb | iex

  Run using Docker

Docker can be used to manage and run SurrealDB database instances without the need to install any command-line tools. The SurrealDB docker container contains the full command-line tools for importing and exporting data from a running server, or for running a server itself.

docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start

Update the image to the latest version:

docker pull surrealdb/surrealdb:latest

  Getting started

Getting started with SurrealDB is as easy as starting up the SurrealDB database server, choosing your platform, and integrating its SDK into your code. You can easily get started with your platform of choice by reading one of our tutorials.

Client side apps
Server side code

  Quick look

With strongly-typed data types, data can be fully modelled right in the database.

UPDATE person SET
	waist = <int> "34.59",
	height = <float> 201,
	score = <decimal> 0.3 + 0.3 + 0.3 + 0.1
;

Store dynamically computed fields which are calculated when retrieved.

CREATE person SET
	birthday = "2007-06-22",
	can_drive = <future> { time::now() > birthday + 18y }
;

Easily work with unstructured or structured data, in schema-less or schema-full mode.

-- Create a schemafull table
DEFINE TABLE user SCHEMAFULL;

-- Specify fields on the user table
DEFINE FIELD name ON TABLE user TYPE object;
DEFINE FIELD name.first ON TABLE user TYPE string;
DEFINE FIELD name.last ON TABLE user TYPE string;
DEFINE FIELD email ON TABLE user TYPE string ASSERT string::is::email($value);

-- Add a unique index on the email field preventing duplicate values
DEFINE INDEX email ON TABLE user COLUMNS email UNIQUE;

-- Create a new event whenever a user changes their email address
DEFINE EVENT email ON TABLE user WHEN $before.email != $after.email THEN (
	CREATE event SET user = $this, time = time::now(), value = $after.email, action = 'email_changed'
);

Connect records together with fully directed graph edge connections.

-- Add a graph edge between user:tobie and article:surreal
RELATE user:tobie->write->article:surreal
	SET time.written = time::now()
;

-- Add a graph edge between specific users and developers
LET $from = (SELECT users FROM company:surrealdb);
LET $devs = (SELECT * FROM user WHERE tags CONTAINS 'developer');
RELATE $from->like->$devs UNIQUE
	SET time.connected = time::now()
;

Query data flexibly with advanced expressions and graph queries.

-- Select a nested array, and filter based on an attribute
SELECT emails[WHERE active = true] FROM person;

-- Select all 1st, 2nd, and 3rd level people who this specific person record knows, or likes, as separate outputs
SELECT ->knows->(? AS f1)->knows->(? AS f2)->(knows, likes AS e3 WHERE influencer = true)->(? AS f3) FROM person:tobie;

-- Select all person records (and their recipients), who have sent more than 5 emails
SELECT *, ->sent->email->to->person FROM person WHERE count(->sent->email) > 5;

-- Select other products purchased by people who purchased this laptop
SELECT <-purchased<-person->purchased->product FROM product:laptop;

-- Select products purchased by people in the last 3 weeks who have purchased the same products that we purchased
SELECT ->purchased->product<-purchased<-person->(purchased WHERE created_at > time::now() - 3w)->product FROM person:tobie;

Store GeoJSON geographical data types, including points, lines and polygons.

UPDATE city:london SET
	centre = (-0.118092, 51.509865),
	boundary = {
		type: "Polygon",
		coordinates: [[
			[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
			[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
			[-0.38314819, 51.37692386]
		]]
	}
;

Write custom embedded logic using JavaScript functions.

CREATE film SET
	ratings = [
		{ rating: 6, user: user:bt8e39uh1ouhfm8ko8s0 },
		{ rating: 8, user: user:bsilfhu88j04rgs0ga70 },
	],
	featured = function() {
		return this.ratings.filter(r => {
			return r.rating >= 7;
		}).map(r => {
			return { ...r, rating: r.rating * 10 };
		});
	}
;

Specify granular access permissions for client and application access.

-- 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
;

  Community

Join our growing community around the world, for help, ideas, and discussions regarding SurrealDB.

  Contributing

We would    for you to get involved with SurrealDB development! If you wish to help, you can learn more about how you can contribute to this project in the contribution guide.

  Security

For security issues, kindly email us at security@surrealdb.com instead of posting a public issue on GitHub.

  License

Source code for SurrealDB is variously licensed under a number of different licenses. A copy of each license can be found in each repository.

For more information, see the licensing information.

Commit count: 3067

cargo fmt