1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![forbid(unsafe_code, non_ascii_idents)]

//! # SQLite arquitecture
//! *Reference:* https://www.sqlite.org/arch.html

use crate::io::SqliteIo;
use crate::pager::SqlitePager;
use crate::result::SqliteResult;
use crate::runtime::SqliteRuntime;

pub mod header;
pub mod io;
#[cfg(feature = "log")]
pub(crate) mod log;
#[macro_use]
pub(crate) mod log_macros;
pub mod pager;
pub mod result;
pub mod runtime;
pub mod traits;
#[macro_use]
pub mod macros;

#[cfg(test)]
mod tests;

#[derive(Debug)]
pub struct SqliteConnection {
  runtime: SqliteRuntime,
}
impl SqliteConnection {
  pub fn open(conn_str: impl AsRef<str>) -> SqliteResult<Self> {
    let io = SqliteIo::open(conn_str)?;
    let pager = SqlitePager::connect(io)?;
    let runtime = SqliteRuntime::start(pager)?;

    Ok(Self { runtime })
  }
  #[cfg(all(debug_assertions, test))]
  pub fn open_sample() -> SqliteResult<Self> {
    let io = SqliteIo::default();
    let pager = SqlitePager::connect(io)?;
    let runtime = SqliteRuntime::start(pager)?;

    Ok(Self { runtime })
  }

  pub fn runtime(&self) -> &SqliteRuntime {
    &self.runtime
  }

  pub fn runtime_mut(&mut self) -> &mut SqliteRuntime {
    &mut self.runtime
  }
}