Skip to main content

SqlFunctions

Struct SqlFunctions 

Source
pub struct SqlFunctions { /* private fields */ }
Expand description

The app’s collations and scalar functions. Coven registers every one on each connection it opens to the store’s database, before any app SQL runs there: the writer, which also migrates, applies other devices’ writes and merges, the readers, and every connection of a read-only handle.

A collation, or a deterministic function, is part of the store’s schema once the schema uses it. At one version it must give the same answer for the same arguments on every device and in every app version that registers that version, and a collation must be a total order: consistent, antisymmetric and transitive, though distinct strings may compare equal. An index keeps its entries as the function gave them when they were written, so a changed answer takes a new version, and a writable open rebuilds the indexes that use it. A CHECK or a synced table’s unique index decides by it which rows every device keeps (§9.2, §9.3), and a generated column keeps what it computed, so a version can’t change while one of those uses it (§4).

Implementations§

Source§

impl SqlFunctions

Source

pub fn collation<F>( self, name: impl Into<String>, version: u32, compare: F, ) -> Self
where F: Fn(&str, &str) -> Ordering + Send + Sync + 'static,

Adds the collation name at version, ordering text by compare. Every change to the order takes a new version. SQLite compares collation names without regard to ASCII case. A name that is SQLite’s own, BINARY, NOCASE or RTRIM, fails the open with DbError::ReservedCollation, and one added twice with DbError::DuplicateCollation. A panic in compare ends the process: SQLite has no way for a comparison to fail, and any answer coven made up could put an index out of order.

Source

pub fn scalar<F, T>( self, name: impl Into<String>, arguments: u8, determinism: Determinism, compute: F, ) -> Self
where F: Fn(&FunctionArguments<'_>) -> Result<T> + Send + Sync + 'static, T: Into<Value>,

Adds the scalar function name, taking exactly arguments arguments, which SQL calls as name(...). compute reads them and returns the result, or an error that fails the statement calling it. SQLite compares function names without regard to ASCII case. A name SQLite or coven already has, or one with coven’s reserved prefix coven_ or _coven_, fails the open with DbError::ReservedFunction, and one added twice with DbError::DuplicateFunction. A deterministic function must take an argument: one that takes none is a constant, which SQL can write as a literal, and fails the open with DbError::ConstantFunction. A deterministic function’s version changes with every change to its results. Every app function is marked safe for triggers and views, which only the app’s own migrations declare. A panic in compute ends the process.

Trait Implementations§

Source§

impl Clone for SqlFunctions

Source§

fn clone(&self) -> SqlFunctions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SqlFunctions

Source§

fn default() -> SqlFunctions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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
§

impl<T> ErasedDestructor for T
where T: 'static,