pub mod params; mod value; pub use params::params_from_iter; use crate::params::*; use crate::value::*; use std::rc::Rc; use std::sync::Arc; #[derive(Debug, thiserror::Error)] pub enum Error { #[error("SQL conversion failure: `{0}`")] ToSqlConversionFailure(BoxError), } impl From for Error { fn from(_err: limbo_core::LimboError) -> Self { todo!(); } } pub(crate) type BoxError = Box; pub type Result = std::result::Result; pub struct Builder { path: String, } impl Builder { pub fn new_local(path: &str) -> Self { Self { path: path.to_string(), } } #[allow(unused_variables, clippy::arc_with_non_send_sync)] pub async fn build(self) -> Result { match self.path.as_str() { ":memory:" => { let io: Arc = Arc::new(limbo_core::MemoryIO::new()?); let db = limbo_core::Database::open_file(io, self.path.as_str())?; Ok(Database { inner: db }) } _ => todo!(), } } } pub struct Database { inner: Arc, } impl Database { pub fn connect(self) -> Result { let conn = self.inner.connect(); Ok(Connection { inner: conn }) } } pub struct Connection { inner: Rc, } impl Connection { pub async fn query(&self, sql: &str, params: impl IntoParams) -> Result { let mut stmt = self.prepare(sql).await?; stmt.query(params).await } pub async fn execute(&self, sql: &str, params: impl IntoParams) -> Result { let mut stmt = self.prepare(sql).await?; stmt.execute(params).await } pub async fn prepare(&self, sql: &str) -> Result { let stmt = self.inner.prepare(sql)?; Ok(Statement { _inner: Rc::new(stmt), }) } } pub struct Statement { _inner: Rc, } impl Statement { pub async fn query(&mut self, params: impl IntoParams) -> Result { let _params = params.into_params()?; todo!(); } pub async fn execute(&mut self, params: impl IntoParams) -> Result { let _params = params.into_params()?; todo!(); } } pub trait IntoValue { fn into_value(self) -> Result; } #[derive(Debug, Clone)] pub enum Params { None, Positional(Vec), Named(Vec<(String, Value)>), } pub struct Transaction {} pub struct Rows { _inner: Rc, } impl Rows { pub async fn next(&mut self) -> Result> { todo!(); } } pub struct Row {} impl Row { pub fn get_value(&self, _index: usize) -> Result { todo!(); } }