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
impl SqlFunctions
Sourcepub fn collation<F>(
self,
name: impl Into<String>,
version: u32,
compare: F,
) -> Self
pub fn collation<F>( self, name: impl Into<String>, version: u32, compare: F, ) -> Self
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.
Sourcepub fn scalar<F, T>(
self,
name: impl Into<String>,
arguments: u8,
determinism: Determinism,
compute: F,
) -> Self
pub fn scalar<F, T>( self, name: impl Into<String>, arguments: u8, determinism: Determinism, compute: F, ) -> Self
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
impl Clone for SqlFunctions
Source§fn clone(&self) -> SqlFunctions
fn clone(&self) -> SqlFunctions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more