The Rust SDK talks to SurrealDB through a Surreal client. To start, create a client for an endpoint, sign in, and select the namespace and database that later calls use.
Surreal::new::<T>(address) creates a client and connects it in one call, where T is the engine that reaches the endpoint, such as Ws for a remote server over WebSocket. Surreal::init() creates a client that is not connected yet, which suits a global static instance, and connect() connects it later. The any engine chooses the engine at runtime from the scheme of a URL, such as ws:// or mem://, so the same code can open an embedded database or connect to a server.
Each method has its own page with its arguments and examples.
| Method | Description |
|---|---|
Surreal::new() | Creates a client and connects it to a local or remote database endpoint |
Surreal::init() | Creates a client that is not connected yet, typically for a global static instance |
db.connect() | Connects a client to a local or remote database endpoint |
db.use_ns() and db.use_db() | Switch to a specific namespace and database |
db.use_defaults() | Selects the namespace and database set by DEFINE CONFIG DEFAULT |
db.wait_for() | Waits for the connection, or for a database to be selected, before proceeding |
db.health() | Runs a lightweight health check on the connection |
db.version() | Returns the version of the server |