1use async_trait::async_trait;
4
5use crate::types::{SqlRow, SqlStatement, SqlTxOptions, SqlValue, StorageResult};
6
7#[async_trait]
9pub trait SqlReader: Send + 'static {
10 async fn query_row(&mut self, statement: SqlStatement) -> StorageResult<Option<SqlRow>>;
12 async fn query_all(&mut self, statement: SqlStatement) -> StorageResult<Vec<SqlRow>>;
14 async fn query_scalar(&mut self, statement: SqlStatement) -> StorageResult<Option<SqlValue>>;
16 async fn explain(&mut self, statement: SqlStatement) -> StorageResult<Vec<SqlRow>>;
18}
19
20#[async_trait]
22pub trait SqlWriter: SqlReader + Send + 'static {
23 async fn execute(&mut self, statement: SqlStatement) -> StorageResult<u64>;
25 async fn execute_batch(&mut self, statements: Vec<SqlStatement>) -> StorageResult<u64>;
27 async fn execute_script(&mut self, script: String) -> StorageResult<()>;
29}
30
31#[async_trait]
33pub trait SqlTransaction: SqlWriter + Send + 'static {
34 async fn commit(self: Box<Self>) -> StorageResult<()>;
36 async fn rollback(self: Box<Self>) -> StorageResult<()>;
38}
39
40#[async_trait]
42pub trait SqlAccess: Send + Sync + 'static {
43 async fn reader(&self) -> StorageResult<Box<dyn SqlReader>>;
45 async fn writer(&self) -> StorageResult<Box<dyn SqlWriter>>;
47 async fn begin_tx(&self, options: SqlTxOptions) -> StorageResult<Box<dyn SqlTransaction>>;
49}