1pub mod adapter;
2pub mod connection;
3pub mod executor;
4pub mod reader;
5pub mod transaction;
6pub mod utils;
7pub mod writer;
8pub mod codec;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum PageType {
12 LeafIndex = 0x0a,
13 LeafTable = 0x0d,
14 InteriorIndex = 0x02,
15 InteriorTable = 0x05,
16}
17
18pub use adapter::SqliteAdapter;
19pub use connection::SqliteConnection;
20pub use transaction::SqliteTransaction;
21pub use codec::{SqliteCodec, SqliteCommand, SqliteResponse};
22
23use futures::{StreamExt, SinkExt};
24use tokio::net::TcpStream;
25use tokio_util::codec::Framed;
26use tracing::{error, info};
27use yykv_types::DsError;
28
29pub type Result<T> = std::result::Result<T, DsError>;
30
31pub async fn handle_connection(stream: TcpStream) -> Result<()> {
33 let mut framed = Framed::new(stream, SqliteCodec);
34 info!("New SQLite connection established");
35
36 while let Some(result) = framed.next().await {
37 match result {
38 Ok(cmd) => {
39 match cmd {
40 SqliteCommand::Execute(sql) => info!("SQLite Execute: {}", sql),
41 SqliteCommand::Query(sql) => info!("SQLite Query: {}", sql),
42 }
43 framed.send(SqliteResponse::Ok).await?;
44 }
45 Err(e) => {
46 error!("SQLite protocol error: {}", e);
47 break;
48 }
49 }
50 }
51
52 Ok(())
53}