import()

Restores the database from a file.

Method Syntax

db.import(source)

Example usage

The following example assumes the presence of a file called backup.surql in the same directory as the current project. To quickly create it, copy and paste the example for the .export() method.

use surrealdb::engine::any::connect;
use surrealdb::opt::auth::Root;

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
let db = connect("http://localhost:8000").await?;
db.signin(Root {
username: "root".to_string(),
password: "secret".to_string(),
})
.await?;
db.use_ns("main").use_db("main").await?;
db.import("backup.surql").await?;
Ok(())
}

See also