Skip to main content

we_trust_sqlite/
adapter.rs

1use crate::connection::SqliteConnection;
2use crate::executor::SqliteExecutor;
3use std::sync::Arc;
4use yykv_types::DsError;
5
6/// Limbo builder
7type LimboBuilder = limbo::Builder;
8
9/// Limbo database wrapper
10type LimboDb = limbo::Database;
11
12/// Limbo connection wrapper
13type LimboConn = limbo::Connection;
14
15type Result<T> = std::result::Result<T, DsError>;
16
17pub struct SqliteAdapter;
18
19impl SqliteAdapter {
20    /// Connect to a SQLite database using Limbo (pure Rust implementation)
21    pub async fn connect(path: &str) -> Result<SqliteConnection> {
22        // Open database using Limbo
23        let db = LimboBuilder::new_local(path).build().await.map_err(|e| DsError::network(None, e.to_string()))?;
24        
25        // Create connection using Limbo
26        let conn = db.connect().map_err(|e| DsError::network(None, e.to_string()))?;
27        let conn = Arc::new(conn);
28        
29        // Create executor using Limbo
30        let executor = Arc::new(SqliteExecutor::new(conn.clone()));
31
32        Ok(SqliteConnection::new(conn, executor))
33    }
34}