Skip to main content

Database

Struct Database 

Source
pub struct Database<P: Policy> { /* private fields */ }
Expand description

One database’s connections and upkeep threads.

Implementations§

Source§

impl<P: Policy> Database<P>

Source

pub fn checkpoints(&self) -> bool

Whether one of the database’s own threads checkpoints its WAL.

Source

pub fn fault_checkpoints( &self, fault: impl FnMut() -> Result<(), PolicyError<P>> + Send + 'static, )

Run fault as each checkpoint takes the writer.

Source

pub fn after_checkpoint_copies(&self, step: impl FnMut() + Send + 'static)

A checkpoint copies the WAL in passes while writes go on. Run step after each pass’s copy returns, before the pass syncs.

Source

pub fn report_checkpoints(&self) -> UnboundedReceiver<WalCheckpoint>

Return a receiver that gets what each later checkpoint does at its last step. The checkpointer sends it while the checkpoint still holds the writer.

Source

pub fn checkpoint_now(&self) -> Result<(), PolicyError<P>>

Run one wake’s checkpoint now, on the checkpointer’s connection.

Source

pub fn report_statistics_runs(&self) -> UnboundedReceiver<()>

Return a receiver that gets a message after each later run of the planner’s statistics commits.

Source

pub fn observe_next_reader_wait(&self) -> Receiver<()> ⓘ

Return a receiver that gets a message when the next caller waits for a reader.

Source

pub fn each_reader(&self, visit: impl FnMut(&mut HostSql<P>))

Run visit on each reader in turn, under its own lock.

Source

pub fn each_connection(&self, visit: impl FnMut(&HostSql<P>))

Run visit on every connection the database holds open, one at a time, each under its own lock: the readers, the upkeep threads’ connections and the writer.

Source§

impl<P: Policy> Database<P>

Source

pub fn open_with<T, E: From<PolicyError<P>>>( path: &Path, handle: Handle<P::Failure>, options: Options<'_, P>, prepare: impl FnOnce(&mut HostSql<P>) -> Result<T, E>, ) -> Result<(Self, T), E>

Open the database at path: its writer, switched to WAL, then prepare on the writer (or on the first reader, as options asks) before the database serves anything; then the statistics, commit capture, upkeep threads and readers options asks for. Every connection then serves handle, which their failures fail.

Source

pub fn host<T>(&self, run: impl FnOnce(&mut HostSql<P>) -> T) -> T

Run run on the writer, once no other call holds it.

Source

pub fn reader(&self) -> Reader<'_, P>

An idle reader, once one is free; it stays the caller’s until the lease drops.

Source

pub fn checkpointed_size(&self) -> CheckpointedSize

A view of the main database file’s size in bytes after the latest checkpoint, which wakes when a later checkpoint changes the size. Before the first checkpoint, the watch holds the file’s size once the commits open_with ran ended. The writer and the checkpointer send the size after each checkpoint they run through HostSql::wal_checkpoint: the checkpointer’s own, and the host’s on the writer.

Two kinds of checkpoint send nothing. SQLite checkpoints the WAL as the database closes, and nothing reads the watch after that, because the watch closes with the database. SQLite’s own automatic checkpoint, which runs inside a commit, sends nothing either; while sqlive’s checkpointer runs, no connection of the database’s runs one. Without the checkpointer, the writer runs one as its wal_autocheckpoint asks.

Source

pub fn close(self) -> Vec<PolicyError<P>> ⓘ

Stop the upkeep threads; gather the planner’s statistics again if the database keeps them and its handle hasn’t failed; then close every connection. Closing goes on past each failure, and returns them all.

Auto Trait Implementations§

§

impl<P> !Freeze for Database<P>

§

impl<P> !RefUnwindSafe for Database<P>

§

impl<P> !UnwindSafe for Database<P>

§

impl<P> Send for Database<P>

§

impl<P> Sync for Database<P>

§

impl<P> Unpin for Database<P>

§

impl<P> UnsafeUnpin for Database<P>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more