rust_query

Struct Database

Source
pub struct Database<S> { /* private fields */ }
Expand description

The primary interface to the database.

It allows creating read and write transactions from multiple threads. It is also safe to create multiple Database instances for the same database (from one or multiple processes).

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 a Transaction can always be made immediately. Making a TransactionMut has to wait until all other TransactionMuts are finished.

Sqlite is also configured with synchronous=NORMAL. This gives better performance by fsyncing less. The database will not lose transactions due to application crashes, but it might due to system crashes or power loss.

§Creating transactions

Creating a transaction requires access to a ThreadToken. This makes it impossible to create two transactions on the same thread, making it impossible to accidentally share a TableRow outside of the transaction that it was created in.

Implementations§

Source§

impl<S> Database<S>

Source

pub fn read<'a>(&self, token: &'a mut ThreadToken) -> Transaction<'a, S>

Create a Transaction. This operation always completes immediately as it does not need to wait on other transactions.

Source

pub fn write_lock<'a>( &self, token: &'a mut ThreadToken, ) -> TransactionMut<'a, S>

Create a TransactionMut. This operation needs to wait for all other TransactionMuts for this database to be finished.

The implementation uses the unlock_notify feature of sqlite. This makes it work across processes.

Auto Trait Implementations§

§

impl<S> !Freeze for Database<S>

§

impl<S> !RefUnwindSafe for Database<S>

§

impl<S> Send for Database<S>
where S: Send,

§

impl<S> Sync for Database<S>
where S: Sync,

§

impl<S> Unpin for Database<S>
where S: Unpin,

§

impl<S> !UnwindSafe for Database<S>

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