Skip to main content

Sqlite

Struct Sqlite 

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

Implementations§

Source§

impl Sqlite

Source

pub fn at(path: impl Into<PathBuf>) -> Self

Source

pub fn memory() -> Self

Source

pub fn app_data(name: impl AsRef<str>) -> Result<Self, DbError>

The database named name ("notes.db": .db by convention) in the app’s data directory, day_process::storage::data_dir(), created if missing: a folder named for the app in the platform’s place for app data (Application Support, %LOCALAPPDATA%, $XDG_DATA_HOME, the Android and HarmonyOS files directory; Day’s docs/fs.md “Where files live”), or DAY_DATA_DIR when a host or a test sets it. 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).

§Errors

Returns an error where the platform has no application data directory, or when the directory cannot be created.

Source

pub fn key(self, key: Secret) -> Self

The database key (feature cipher; other builds refuse it at open, loudly).

Source

pub fn cipher_migrate(self) -> Self

Accept a file written by an older SQLCipher generation (PRAGMA cipher_migrate).

Source

pub fn wal(self, on: bool) -> Self

Source

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.

§Errors

Returns an error where the platform has no application data directory.

Source

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.

Source

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

Source§

type Connection = RusqliteConn

Source§

fn open(self) -> Result<RusqliteConn, DbError>

Open the connection. Read more
Source§

fn capabilities(&self) -> Capabilities

Auto Trait Implementations§

§

impl !RefUnwindSafe for Sqlite

§

impl !Send for Sqlite

§

impl !Sync for Sqlite

§

impl !UnwindSafe for Sqlite

§

impl Forget for Sqlite

§

impl Freeze for Sqlite

§

impl Move for Sqlite

§

impl Unpin for Sqlite

§

impl UnsafeUnpin for Sqlite

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> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.