Skip to main content

Sqlite

Sqlite services support.

Capabilities

This service can be used to:

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

Configuration

  • root: Set the working directory of OpenDAL
  • connection_string: Set the connection string of sqlite database
  • table: Set the table of sqlite
  • key_field: Set the key field of sqlite
  • value_field: Set the value field of sqlite

Example

Via Builder

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

#[tokio::main]
async fn main() -> Result<()> {
let mut builder = Sqlite::default();
builder.root("/");
builder.connection_string("file//abc.db");
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::services::Sqlite;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {

let mut map = HashMap::new();
map.insert("connection_string".to_string(), "file//abc.db".to_string());
map.insert("table".to_string(), "your_table".to_string());
map.insert("key_field".to_string(), "your_key_field".to_string());
map.insert("value_field".to_string(), "your_value_field".to_string());

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