SurrealDB Docs Logo

Enter a search query

new()

Connects to a local or remote database endpoint.

Method Syntax
Surreal::new::<T>(address)

Arguments

ArgumentDescription
endpoint

The database endpoint to connect to.

Example usage

use surrealdb::engine::remote::ws::Ws; use surrealdb::Surreal; #[tokio::main] async fn main() -> surrealdb::Result<()> { let db = Surreal::new::<Ws>("127.0.0.1:8000").await?; Ok(()) }

To make a new connection that includes SurrealKV versioning, add the “surreal-kv” feature flag to the surrealdb dependency in Cargo.toml, add the path to the folder containing the database inside new(), and call the .versioned() method.

use surrealdb::engine::local::SurrealKv; use surrealdb::Surreal; #[tokio::main] async fn main() -> surrealdb::Result<()> { let db = Surreal::new::<SurrealKv>("path/to/database-folder").versioned().await?; Ok(()) }

See also