1#![warn(missing_docs)]
2
3pub mod adapter;
4pub mod codec;
5pub mod connection;
6pub mod executor;
7pub mod transaction;
8pub mod utils;
9
10pub use adapter::SqliteAdapter;
11pub use codec::{SqliteCodec, SqliteCommand, SqliteResponse};
12pub use connection::SqliteConnection;
13pub use transaction::SqliteTransaction;
14
15use futures::{SinkExt, StreamExt};
16use tokio::net::TcpStream;
17use tokio_util::codec::Framed;
18use tracing::{error, info};
19use yykv_types::DsError;
20
21pub type Result<T> = std::result::Result<T, DsError>;
22
23pub async fn handle_connection(stream: TcpStream) -> Result<()> {
25 let mut framed = Framed::new(stream, SqliteCodec);
26 info!("New SQLite connection established");
27
28 while let Some(result) = framed.next().await {
29 match result {
30 Ok(cmd) => {
31 match cmd {
32 SqliteCommand::Execute(sql) => info!("SQLite Execute: {}", sql),
33 SqliteCommand::Query(sql) => info!("SQLite Query: {}", sql),
34 }
35 framed.send(SqliteResponse::Ok).await?;
36 }
37 Err(e) => {
38 error!("SQLite protocol error: {}", e);
39 break;
40 }
41 }
42 }
43
44 Ok(())
45}