pub struct Config {
pub synchronous: Synchronous,
pub foreign_keys: ForeignKeys,
/* private fields */
}Expand description
Config is used to open a database from a file or in memory.
This is the first step in the Config -> Migrator -> Database chain to get a Database instance.
§Sqlite config
Sqlite is configured to be in WAL mode. The effect of this mode is that there can be any number of readers with one concurrent writer. What is nice about this is that an immutable crate::Transaction can always be made immediately. Making a mutable crate::Transaction has to wait until all other mutable crate::Transactions are finished.
Fields§
§synchronous: SynchronousConfigure how often SQLite will synchronize the database to disk.
The default is Synchronous::Full.
foreign_keys: ForeignKeysConfigure how foreign keys should be checked.
The default is ForeignKeys::SQLite, but this is likely to change to ForeignKeys::Rust.
Implementations§
Source§impl Config
impl Config
Sourcepub fn open(p: impl AsRef<Path>) -> Self
pub fn open(p: impl AsRef<Path>) -> Self
Open a database that is stored in a file. Creates the database if it does not exist.
Opening the same database multiple times at the same time is fine, as long as they migrate to or use the same schema. All locking is done by SQLite, so connections can even be made using different client implementations.
IMPORTANT: rust-query uses SQLite in WAL mode. While a connection to the database is open there will
be an additional file with the same name as the database, but with -wal appended.
This “write ahead log” is automatically removed when the last connection to the database closes cleanly.
Any -wal file should be considered an integral part of the database and as such should be kept together.
For more details see https://sqlite.org/howtocorrupt.html.
Sourcepub fn open_in_memory() -> Self
pub fn open_in_memory() -> Self
Creates a new empty database in memory.
Sourcepub fn init_stmt(self, sql: &'static str) -> Self
pub fn init_stmt(self, sql: &'static str) -> Self
Append a raw sql statement to be executed if the database was just created.
The statement is executed after creating the empty database and executing all previous statements.
crate::migration::Migrator::fixup should be prefered over this method.