pub struct Sqlite { /* private fields */ }Expand description
A SQLite [Driver] that opens connections to a file or in-memory database.
§Examples
use toasty_driver_sqlite::Sqlite;
let driver = Sqlite::in_memory();Implementations§
Source§impl Sqlite
impl Sqlite
Sourcepub fn new(url: impl Into<String>) -> Result<Self>
pub fn new(url: impl Into<String>) -> Result<Self>
Create a new SQLite driver with an arbitrary connection URL
Sourcepub fn foreign_keys(self, on: bool) -> Self
pub fn foreign_keys(self, on: bool) -> Self
Set the enforcement of foreign key constraints.
Enabled by default.
Sourcepub fn busy_timeout(self, timeout: Duration) -> Self
pub fn busy_timeout(self, timeout: Duration) -> Self
Set how long a connection waits for a lock held by another
connection before failing with database is locked.
Set through sqlite3_busy_timeout as soon as each connection opens,
before any pragma runs. The default is 5 seconds.
Sourcepub fn journal_mode(self, mode: JournalMode) -> Self
pub fn journal_mode(self, mode: JournalMode) -> Self
Set the journal mode.
Journal modes are per connection, except for WAL, which the database file keeps. Opening a WAL database with a different journal mode takes an exclusive lock and converts the file.
Not set by default, so an existing database keeps its mode.
§Examples
use toasty_driver_sqlite::{JournalMode, Sqlite};
let driver = Sqlite::open("app.db").journal_mode(JournalMode::Wal);Sourcepub fn synchronous(self, synchronous: Synchronous) -> Self
pub fn synchronous(self, synchronous: Synchronous) -> Self
Set the synchronous setting.
Not set by default; SQLite’s default is FULL. NORMAL is usually
enough in WAL mode.
Sourcepub fn locking_mode(self, mode: LockingMode) -> Self
pub fn locking_mode(self, mode: LockingMode) -> Self
Set the locking mode.
Not set by default; SQLite’s default is NORMAL.
Sourcepub fn auto_vacuum(self, auto_vacuum: AutoVacuum) -> Self
pub fn auto_vacuum(self, auto_vacuum: AutoVacuum) -> Self
Set the auto-vacuum setting.
Not set by default; SQLite’s default is NONE. On an existing
database the change takes effect only after a VACUUM.
Sourcepub fn page_size(self, page_size: u32) -> Self
pub fn page_size(self, page_size: u32) -> Self
Set the page size in bytes.
Not set by default; SQLite’s default is 4096. On an existing
database the change takes effect only after a VACUUM, and never in
WAL mode.
Sourcepub fn pragma<K, V>(self, key: K, value: V) -> Self
pub fn pragma<K, V>(self, key: K, value: V) -> Self
Set a PRAGMA applied to every connection this driver opens.
Use this for pragmas without a dedicated method. The driver writes
PRAGMA {key} = {value} with both arguments as given, so the caller
supplies any quoting the value needs. Do not pass untrusted input:
the value is SQL text.
Pragmas run in a fixed order rather than the order they are set,
because SQLite and SQLCipher constrain it: key and the other
SQLCipher settings come first, then page_size, locking_mode,
auto_vacuum, journal_mode, foreign_keys, synchronous, and
then every other pragma in the order first set. Setting the same
pragma twice keeps the last value. Names match exactly.
§Examples
use toasty_driver_sqlite::Sqlite;
let driver = Sqlite::open("app.db")
.pragma("cache_size", "-64000")
.pragma("temp_store", "MEMORY");Values of key and other secret SQLCipher pragmas are kept out of
query logs, error messages, and Debug output.
Trait Implementations§
Source§impl Driver for Sqlite
impl Driver for Sqlite
Source§fn capability(&self) -> &'static Capability
fn capability(&self) -> &'static Capability
Source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
cx: &'life1 ConnectContext,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
cx: &'life1 ConnectContext,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn max_connections(&self) -> Option<usize>
fn max_connections(&self) -> Option<usize>
Some(1) for the in-memory SQLite driver which cannot be pooled.Source§fn generate_migration(&self, schema_diff: &Schema<'_>) -> Migration
fn generate_migration(&self, schema_diff: &Schema<'_>) -> Migration
diff::Schema].