Struct SqliteConnection

Source
pub struct SqliteConnection { /* private fields */ }

Implementations§

Source§

impl SqliteConnection

Source

pub fn open(conn_str: impl AsRef<str>) -> SqliteResult<Self>

Examples found in repository?
examples/sqlite_info.rs (line 25)
17  fn run() -> AppResult<()> {
18    let files = [
19      "./data/flights-initial.db",
20      "./data/flights-populated.db",
21      "./data/flights-deleted.db",
22      "./data/mydatabase.db",
23    ];
24    files.iter().try_for_each(|file_path| -> AppResult<()> {
25      let conn = SqliteConnection::open(format!("sqlite://{file_path}"))?;
26      // let sqlite_database = Self::read_bytes(&file)?;
27
28      println!("[{file_path}]:");
29      Self::print_sqlite_info(&conn)?;
30      Ok(())
31    })?;
32
33    Ok(())
34  }
Source

pub fn runtime(&self) -> &SqliteRuntime

Examples found in repository?
examples/sqlite_info.rs (line 40)
36  fn print_sqlite_info(conn: &SqliteConnection) -> AppResult<()> {
37    const LABEL_WIDTH: usize = 21;
38
39    // TODO:
40    let sqlite_header = conn.runtime().header();
41
42    let mut output = "".to_owned();
43
44    output.push_str(&format!(
45      "{label: <w$}{value}\n",
46      w = LABEL_WIDTH,
47      label = "database page size:",
48      value = u32::from(sqlite_header.page_size())
49    ));
50    output.push_str(&format!(
51      "{label: <w$}{value}\n",
52      w = LABEL_WIDTH,
53      label = "write format:",
54      value =
55        u8::from(sqlite_header.file_format_version_numbers().write_version())
56    ));
57    output.push_str(&format!(
58      "{label: <w$}{value}\n",
59      w = LABEL_WIDTH,
60      label = "read format:",
61      value =
62        u8::from(sqlite_header.file_format_version_numbers().read_version())
63    ));
64    output.push_str(&format!(
65      "{label: <w$}{value}\n",
66      w = LABEL_WIDTH,
67      label = "reserved bytes:",
68      value = **sqlite_header.reserved_bytes_per_page()
69    ));
70    output.push_str(&format!(
71      "{label: <w$}{value}\n",
72      w = LABEL_WIDTH,
73      label = "file change counter:",
74      value = **sqlite_header.file_change_counter()
75    ));
76
77    output.push_str(&format!(
78      "{label: <w$}{value}\n",
79      w = LABEL_WIDTH,
80      label = "database page count:",
81      value = **sqlite_header.db_filesize_in_pages()
82    ));
83
84    output.push_str(&format!(
85      "{label: <w$}{value}\n",
86      w = LABEL_WIDTH,
87      label = "freelist page count:",
88      value = **sqlite_header.freelist_pages().total()
89    ));
90
91    output.push_str(&format!(
92      "{label: <w$}{value}\n",
93      w = LABEL_WIDTH,
94      label = "schema cookie:",
95      value = **sqlite_header.schema_cookie()
96    ));
97
98    output.push_str(&format!(
99      "{label: <w$}{value}\n",
100      w = LABEL_WIDTH,
101      label = "schema format:",
102      value = u32::from(sqlite_header.schema_format())
103    ));
104
105    output.push_str(&format!(
106      "{label: <w$}{value}\n",
107      w = LABEL_WIDTH,
108      label = "default cache size:",
109      value = **sqlite_header.suggested_cache_size()
110    ));
111
112    output.push_str(&format!(
113      "{label: <w$}{value}\n",
114      w = LABEL_WIDTH,
115      label = "autovacuum top root:",
116      value = **sqlite_header
117        .incremental_vacuum_settings()
118        .largest_root_btree_page()
119    ));
120
121    output.push_str(&format!(
122      "{label: <w$}{value}\n",
123      w = LABEL_WIDTH,
124      label = "incremental vacuum:",
125      value = u32::from(
126        sqlite_header
127          .incremental_vacuum_settings()
128          .incremental_vacuum_mode()
129      )
130    ));
131
132    output.push_str(&format!(
133      "{label: <w$}{value}\n",
134      w = LABEL_WIDTH,
135      label = "text encoding:",
136      value = sqlite_header.database_text_encoding()
137    ));
138
139    output.push_str(&format!(
140      "{label: <w$}{value}\n",
141      w = LABEL_WIDTH,
142      label = "user version:",
143      value = **sqlite_header.user_version()
144    ));
145
146    output.push_str(&format!(
147      "{label: <w$}{value}\n",
148      w = LABEL_WIDTH,
149      label = "application id:",
150      value = **sqlite_header.application_id()
151    ));
152
153    output.push_str(&format!(
154      "{label: <w$}{value}\n",
155      w = LABEL_WIDTH,
156      label = "software version:",
157      value = **sqlite_header.write_library_version()
158    ));
159
160    println!("{output}");
161    Ok(())
162  }
Source

pub fn runtime_mut(&mut self) -> &mut SqliteRuntime

Trait Implementations§

Source§

impl Debug for SqliteConnection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.