Skip to main content

LibSQL

libSQL service support.

Capabilities

This service can be used to:

  • stat
  • read
  • write
  • create_dir
  • delete
  • copy
  • rename
  • list
  • scan
  • presign
  • blocking

Configuration

  • root: Set the working directory of OpenDAL
  • connection_string: Set the connection string for libsql server
  • auth_token: Set the authentication token for libsql server
  • table: Set the table of libsql
  • key_field: Set the key field of libsql
  • value_field: Set the value field of libsql

Example

Via Builder

use anyhow::Result;
use opendal::services::Libsql;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut builder = Libsql::default();
builder.root("/");
builder.connection_string("https://example.com/db");
builder.auth_token("secret");
builder.table("your_table");
// key field type in the table should be compatible with Rust's &str like text
builder.key_field("key");
// value field type in the table should be compatible with Rust's Vec<u8> like bytea
builder.value_field("value");

let op = Operator::new(builder)?.finish();
Ok(())
}

Via Config

use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("root".to_string(), "/".to_string());
map.insert("connection_string".to_string(), "https://example.com/db".to_string());
map.insert("auth_token".to_string(), "secret".to_string());
map.insert("table".to_string(), "your_table".to_string());
map.insert("key_field".to_string(), "key".to_string());
map.insert("value_field".to_string(), "value".to_string());

let op: Operator = Operator::via_map(Scheme::Libsql, map)?;
Ok(())
}