Config

Struct Config 

Source
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: Synchronous

Configure how often SQLite will synchronize the database to disk.

The default is Synchronous::Full.

§foreign_keys: ForeignKeys

Configure how foreign keys should be checked.

The default is ForeignKeys::SQLite, but this is likely to change to ForeignKeys::Rust.

Implementations§

Source§

impl Config

Source

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.

Source

pub fn open_in_memory() -> Self

Creates a new empty database in memory.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Config

§

impl !RefUnwindSafe for Config

§

impl !Send for Config

§

impl !Sync for Config

§

impl Unpin for Config

§

impl !UnwindSafe for Config

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V