pub struct Sqlite { /* private fields */ }Implementations§
Source§impl Sqlite
impl Sqlite
pub fn at(path: impl Into<PathBuf>) -> Self
pub fn memory() -> Self
Sourcepub fn app_data(name: impl AsRef<str>) -> Result<Self, DbError>
pub fn app_data(name: impl AsRef<str>) -> Result<Self, DbError>
The database named name in the per-app data directory, created if missing. The
directory follows the day-part-filesystem root rules (docs/fs.md): DAY_DATA_DIR when the
host passes one (the Android and OpenHarmony hosts do), the platform’s app-data
convention otherwise, and a day-db/ leaf of its own beside day-part-filesystem’ day-fs/.
name is a file name, not a path. Errs where no such directory exists (web has no
filesystem; keep a wasm build on Sqlite::memory or its own driver).
Sourcepub fn key(self, key: Secret) -> Self
pub fn key(self, key: Secret) -> Self
The database key (feature cipher; other builds refuse it at open, loudly).
Sourcepub fn cipher_migrate(self) -> Self
pub fn cipher_migrate(self) -> Self
Accept a file written by an older SQLCipher generation (PRAGMA cipher_migrate).
pub fn wal(self, on: bool) -> Self
Sourcepub fn app_data_dir() -> Result<PathBuf, DbError>
pub fn app_data_dir() -> Result<PathBuf, DbError>
The directory Sqlite::app_data resolves into, for apps that manage their document
files there (numbering “Drawing 2”, importing a picked file). Created lazily by
app_data; this accessor only resolves it.
Sourcepub fn with_init(self, f: impl Fn(&Connection) + 'static) -> Self
pub fn with_init(self, f: impl Fn(&Connection) + 'static) -> Self
A per-connection hook over the raw rusqlite connection: the escape valve for loadable extensions, custom functions, and PRAGMAs this crate does not model. Native only.
Sourcepub fn trace_sql(self, f: impl Fn(&str) + 'static) -> Self
pub fn trace_sql(self, f: impl Fn(&str) + 'static) -> Self
Per-statement SQL tracing through the engine’s own facility (sqlite3_trace_v2 with
SQLITE_TRACE_STMT): f sees every statement this connection executes (migrations,
autosave flushes, live-query SELECTs, maintenance) with bound parameters expanded by
the engine itself. Wire it to a logger in debug builds:
let driver = Sqlite::app_data("trips.db")?;
let driver = if cfg!(debug_assertions) {
driver.trace_sql(|sql| log::trace!("sql: {sql}"))
} else {
driver
};The trace installs after any PRAGMA key, so a cipher key never reaches the sink. On
web-dom a file database’s engine runs in the day-sql worker, out of closure reach:
there the statements log to the browser console ([day-sql] lines in devtools) and
f is not called. :memory: databases call f on every target.
Trait Implementations§
Source§impl SqliteDriver for Sqlite
impl SqliteDriver for Sqlite
type Connection = RusqliteConn
fn open(self) -> Result<RusqliteConn, DbError>
fn capabilities(&self) -> Capabilities
Auto Trait Implementations§
impl !RefUnwindSafe for Sqlite
impl !Send for Sqlite
impl !Sync for Sqlite
impl !UnwindSafe for Sqlite
impl Freeze for Sqlite
impl Unpin for Sqlite
impl UnsafeUnpin for Sqlite
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more