use std::path::Path;
mod connect;
mod journal_mode;
mod parse;
use crate::connection::LogSettings;
pub use journal_mode::SqliteJournalMode;
use std::{borrow::Cow, time::Duration};
#[derive(Clone, Debug)]
pub struct SqliteConnectOptions {
pub(crate) filename: Cow<'static, Path>,
pub(crate) in_memory: bool,
pub(crate) read_only: bool,
pub(crate) create_if_missing: bool,
pub(crate) journal_mode: SqliteJournalMode,
pub(crate) foreign_keys: bool,
pub(crate) shared_cache: bool,
pub(crate) statement_cache_capacity: usize,
pub(crate) busy_timeout: Duration,
pub(crate) log_settings: LogSettings,
}
impl Default for SqliteConnectOptions {
fn default() -> Self {
Self::new()
}
}
impl SqliteConnectOptions {
pub fn new() -> Self {
Self {
filename: Cow::Borrowed(Path::new(":memory:")),
in_memory: false,
read_only: false,
create_if_missing: false,
foreign_keys: true,
shared_cache: false,
statement_cache_capacity: 100,
journal_mode: SqliteJournalMode::Wal,
busy_timeout: Duration::from_secs(5),
log_settings: Default::default(),
}
}
pub fn filename(mut self, filename: impl AsRef<Path>) -> Self {
self.filename = Cow::Owned(filename.as_ref().to_owned());
self
}
pub fn foreign_keys(mut self, on: bool) -> Self {
self.foreign_keys = on;
self
}
pub fn journal_mode(mut self, mode: SqliteJournalMode) -> Self {
self.journal_mode = mode;
self
}
pub fn read_only(mut self, read_only: bool) -> Self {
self.read_only = read_only;
self
}
pub fn create_if_missing(mut self, create: bool) -> Self {
self.create_if_missing = create;
self
}
pub fn statement_cache_capacity(mut self, capacity: usize) -> Self {
self.statement_cache_capacity = capacity;
self
}
pub fn busy_timeout(mut self, timeout: Duration) -> Self {
self.busy_timeout = timeout;
self
}
}