1pub mod file_header;
2mod helpers;
3mod io;
4mod macros;
5pub mod result;
6mod runtime;
7mod traits;
8
9use std::sync::OnceLock;
10
11use crate::{result::SqliteResult, runtime::SqliteRuntime};
12
13pub use crate::helpers::SqliteRecord;
14
15static VERSION_NUMBER: OnceLock<u32> = OnceLock::new();
16
17#[derive(Debug)]
18pub struct SqliteConnection {
19 runtime: SqliteRuntime,
20}
21
22impl SqliteConnection {
23 pub fn connect<S: AsRef<str>>(conn_str: S) -> SqliteResult<Self> {
24 bootstrap();
25 let runtime = SqliteRuntime::start(conn_str)?;
26 Ok(Self { runtime })
27 }
28 pub fn run_query(&mut self, query_str: &str) -> SqliteResult<SqliteRecord> {
29 self.runtime.run_query(query_str)
30 }
31}
32
33fn bootstrap() {
34 VERSION_NUMBER.get_or_init(|| {
35 let mut s = env!("CARGO_PKG_VERSION").split('.');
36 let release = s.next().and_then(|x| x.parse().ok()).unwrap_or(0u32);
37 let major = s.next().and_then(|x| x.parse().ok()).unwrap_or(0u32);
38 let minor = s.next().and_then(|x| x.parse().ok()).unwrap_or(0u32);
39
40 (10_000 * release) + (100 * major) + minor
41 });
42}