rsdbc_sqlite/
connection.rs

1use futures::future::BoxFuture;
2use rsdbc_core::connection::{Batch, Connection, ConnectionFactory, ConnectionFactoryMetadata, ConnectionFactoryOptions, ConnectionFactoryProvider, ConnectionMetadata, IsolationLevel, Statement, ValidationDepth};
3use rsdbc_core::error::RsdbcErrors;
4use rsdbc_core::OptionValue;
5use crate::error::SqliteRsdbcError;
6use crate::options::SqliteConnectOptions;
7
8pub struct SqliteConnection;
9impl Connection for SqliteConnection {
10    fn begin_transaction(&mut self) -> rsdbc_core::Result<()> {
11        todo!()
12    }
13
14    fn close(&mut self) -> rsdbc_core::Result<()> {
15        todo!()
16    }
17
18    fn commit_transaction(&mut self) {
19        todo!()
20    }
21
22    fn create_batch(&mut self) -> rsdbc_core::Result<Box<dyn Batch>> {
23        todo!()
24    }
25
26    fn create_savepoint(&mut self, name: &str) {
27        todo!()
28    }
29
30    fn create_statement(&mut self, sql: &str) -> rsdbc_core::Result<Box<dyn Statement<'_> + '_>> {
31        todo!()
32    }
33
34    fn is_auto_commit(&mut self) -> bool {
35        todo!()
36    }
37
38    fn metadata(&mut self) -> rsdbc_core::Result<Box<dyn ConnectionMetadata>> {
39        todo!()
40    }
41
42    fn transaction_isolation_level(&mut self) -> IsolationLevel {
43        todo!()
44    }
45
46    fn release_savepoint(&mut self, name: &str) {
47        todo!()
48    }
49
50    fn rollback_transaction(&mut self) {
51        todo!()
52    }
53
54    fn rollback_transaction_to_savepoint(&mut self, name: String) {
55        todo!()
56    }
57
58    fn auto_commit(&mut self, commit: bool) {
59        todo!()
60    }
61
62    fn set_transaction_isolation_level(&mut self, isolation_level: IsolationLevel) {
63        todo!()
64    }
65
66    fn validate(&mut self, depth: ValidationDepth) -> bool {
67        todo!()
68    }
69}
70
71pub struct SqliteConnectionMetadata {
72
73}
74
75impl ConnectionMetadata for SqliteConnectionMetadata {
76    fn database_product_name(&self) -> &str {
77        todo!()
78    }
79
80    fn database_version(&self) -> &str {
81        todo!()
82    }
83}
84
85
86
87pub struct SqliteConnectionFactory {
88    pub configuration: SqliteConnectOptions,
89}
90
91impl ConnectionFactory for SqliteConnectionFactory {
92    fn connect(&self) -> BoxFuture<'_, rsdbc_core::Result<Box<dyn Connection>>> {
93        todo!()
94    }
95
96    fn get_metadata(&self) -> Box<dyn ConnectionFactoryMetadata> {
97        todo!()
98    }
99}
100
101
102// TODO: use From trait instead?
103impl ConnectionFactoryProvider for SqliteConnectionFactory {
104    type C = SqliteConnectionFactory;
105
106    fn create(connection_factory_options: ConnectionFactoryOptions) -> rsdbc_core::Result<Self::C> {
107        // TODO: map options to sqlite options
108        // TODO: prefer non-consuming builder - https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
109        let mut sqlite_options = SqliteConnectOptions::new();
110
111        // TODO: just testing how this would work
112        let protocol = connection_factory_options.options.get("protocol");
113        if let Some(protocol) = protocol {
114            let protocol_value = match protocol {
115                OptionValue::String(s) => {
116                    s.to_string()
117                }
118                _ => {
119                    // TODO: return error here
120                    "".to_string()
121                }
122            };
123            if protocol_value == "memory" {
124
125            } else {
126                sqlite_options = sqlite_options.filename(protocol_value);
127            }
128        } else {
129            return Err(RsdbcErrors::from(SqliteRsdbcError::InvalidProtocol("".to_string())));
130        }
131
132        Ok(SqliteConnectionFactory {
133            configuration: sqlite_options
134        })
135
136    }
137}