4 releases (stable)

2.0.0 Jul 24, 2024
1.5.5 Jul 24, 2024
0.1.0 Jul 20, 2024

#2820 in Database interfaces

MIT/Apache

7KB
73 lines

SurrealDB Client

A Rust client library for interacting with SurrealDB.

Features

  • Simple and easy-to-use API
  • Customizable client options
  • Asynchronous SQL execution

Usage

Add this to your Cargo.toml:

[dependencies]
surrealdb_client = "2.0.0"

Here's a quick example:

Using with default settings:

use surrealdb_client::{SurrealDBClient, ClientOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let default_client = SurrealDBClient::new(ClientOptions::default())?;
    let result = default_client.execute_sql("SELECT * FROM accounts").await?;
    println!("Result: {}", result);
    Ok(())
}

Using with user settings:

use surrealdb_client::{SurrealDBClient, ClientOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let custom_options = ClientOptions::new(
        "crypto".to_string(),
        "crypto".to_string(),
        "http://localhost:8000/sql".to_string(),
        Some("root".to_string()),
        Some("root".to_string()),
    );
    let custom_client = SurrealDBClient::new(custom_options)?;
    let result = custom_client.execute_sql("SELECT * FROM accounts").await?;
    println!("Result: {}", result);
    Ok(())
}

Compatibility

Crate Version Compatible SurrealDB Version
1.5.5 1.5.4
2.0.0 v2.0.0-alpha.7

License

This project is licensed under either of

at your option.

Dependencies

~6–18MB
~258K SLoC