pub mod error;
mod open_flag;
mod database;
mod statement;
mod raii;
pub use error::DatabaseError;
pub use open_flag::OpenFlag;
pub use database::{Database, DatabaseExt};
pub use statement::{Statement, StatementExt};
pub use raii::{SqliteHandle, StatementHandle, SqliteMutexGuard};
macro_rules! flags {
($(#[$doc:meta])* $id:ident, $($(#[$doc2:meta])* $fl:ident => $name:ident),* $(,)?) => {
$(#[$doc])*
#[derive(Debug, PartialEq, Eq)]
pub enum $id {
$($(#[$doc2])* $name),*
}
impl $id {
pub fn from_code(code: i32) -> Option<Self> {
match code {
$(libsqlite3_sys::$fl => Some(Self::$name)),*,
_ => None
}
}
}
};
}
flags! {
DataType,
SQLITE_NULL => Null,
SQLITE_INTEGER => Int,
SQLITE_FLOAT => Float,
SQLITE3_TEXT => Text,
SQLITE_BLOB => Blob,
}
impl std::fmt::Display for DataType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DataType::Null => f.write_str("null"),
DataType::Int => f.write_str("int"),
DataType::Float => f.write_str("double"),
DataType::Text => f.write_str("text"),
DataType::Blob => f.write_str("blob"),
}
}
}
flags! {
StepResult,
SQLITE_DONE => Done,
SQLITE_ROW => Row,
}
impl StepResult {
pub fn is_done(&self) -> bool {
matches!(self, StepResult::Done)
}
pub fn is_row(&self) -> bool {
matches!(self, StepResult::Row)
}
}
pub fn is_threadsafe() -> bool {
const SERIALIZE_MODE: i32 = 1;
unsafe { libsqlite3_sys::sqlite3_threadsafe() == SERIALIZE_MODE }
}