Skip to main content

Module database

Module database 

Source
Expand description

The application’s SurrealDB database.

The app connects to a SurrealDB server (self-hosted or SurrealDB Cloud) over WebSocket and runs SurrealQL through the surrealdb SDK. Several processes and machines can share the database. Configure it with SURREAL_URL, SURREAL_NS, SURREAL_DB, SURREAL_USER, SURREAL_PASS and SURREAL_AUTH_LEVEL (see DatabaseConfig::from_env).

Schema changes are SurrealQL files in database/migrations/, applied in order by migrations.

Modules§

migrations
Schema migrations: SurrealQL files applied in order.

Structs§

DatabaseConfig
Where to connect and how to sign in.

Enums§

AuthLevel
Where a SurrealDB user is defined, which decides how to sign in.

Constants§

AUTH_LEVEL_ENV
DATABASE_ENV
DEFAULT_URL
The server used when SURREAL_URL is not set: surreal start on this machine.
NAMESPACE_ENV
PASSWORD_ENV
TRANSACTION_ATTEMPTS
How many times transaction! runs a transaction that keeps failing with a conflict (see is_transaction_conflict) before giving up.
URL_ENV
USER_ENV

Traits§

Executor
Runs SurrealQL: the database (Db) or a Transaction. Write helper functions against &impl Executor to use them in and out of transactions.
MaybeConflict
Errors that may be a transaction conflict, so transaction! knows when to retry.

Functions§

connect
Connects, signs in and selects the namespace and database.
is_already_exists
Whether err is a write rejected by a UNIQUE index or an existing record ID.
is_transaction_conflict
Whether err is a transaction that lost a race with a concurrent one; running it again usually succeeds (up to TRANSACTION_ATTEMPTS times).

Type Aliases§

Db
A connection to the database. Cheap to clone: clones share the connection.
Transaction
A transaction started by transaction!.