Rust

adapter

Module

[Adapter]: the storage engine under a crate::Database.

Adapters in this crate: postgres::Postgres (feature postgres), mariadb::MariaDB (feature mariadb; MariaDB and, with feature mysql, MySQL), sqlite::Sqlite (feature sqlite), memory::Memory (feature memory), mongo::Mongo (feature mongo), redis::Redis (feature redis) and pool::Pool (feature pool), over a pool of adapters.

Contents

40 submodules, and what the module defines itself.

use utopia_database::adapter::FindOptions;
Rust
pub struct FindOptions<'a>

The arguments of Adapter::find besides the collection and queries.

use utopia_database::adapter::State;
Rust
pub struct State

Undocumented.

Also implements Default.
use utopia_database::adapter::StateInner;
Rust
pub struct StateInner

The fields of State.

use utopia_database::Adapter;
Rust
pub trait Adapter: Send + Sync

A storage engine. See the module docs.

use utopia_database::adapter::with_transaction;
Rust
pub async fn with_transaction<A, T, F, Fut>(adapter: &A, mut f: F) -> Result<T> where A: Adapter + ?Sized, F: FnMut() -> Fut, Fut: Future<Output = Result<T>>,

$adapter->withTransaction($callback): runs f in a transaction, committing on success and rolling back on failure. Failures other than duplicate, restricted, authorization, relationship, conflict, limit and timeout errors are retried twice, after 50 ms and 100 ms.

Rust
pub type Transform = Arc<dyn Fn(String) -> String + Send + Sync>

A statement transform registered with [Adapter::before]: receives the SQL about to run and returns the SQL to run instead.

Rust
pub const EVENT_ALL: &str = "*"

Database::EVENT_ALL: transforms registered for every statement.

adapter::mariadb

Own page

[MariaDB]: the MariaDB adapter, and with Flavor::MySQL (feature mysql) the MySQL adapter.

use utopia_database::adapter::mariadb::MariaDB;
Rust
pub struct MariaDB

The MariaDB (or MySQL) adapter. See the module docs.

use utopia_database::adapter::mariadb::Flavor;
Rust
pub enum Flavor

Undocumented.

adapter::mariadb::ddl

Own page

Databases, tables, columns, relationship columns and indexes, and the schema as the server reports it.

adapter::mariadb::documents

Own page

Documents: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.

adapter::mariadb::find

Own page

Finds, counts and sums: WHERE conditions for every query method (comparisons, LIKE, REGEXP, MATCH ... AGAINST full-text search, JSON arrays, spatial filters), cursor pagination and the document-level permission filter.

adapter::mariadb::operators

Own page

Operators: atomic updates as SQL expressions over MariaDB's (and MySQL's) JSON functions, and their effect on a default value for documents an upsert creates.

adapter::mariadb::pdo

Own page

The adapter writes SQL with named placeholders (:_uid) and binds values with a PDO parameter type. PDO (ATTR_EMULATE_PREPARES) substitutes the placeholders client side with quoted literals and sends the statement as text (mysql_real_query, multi statements allowed); with ATTR_STRINGIFY_FETCHES every fetched value is a string. Pdo reproduces that over mysql_async's text protocol, so the server sees the same bytes and the adapter reads the same values:

use utopia_database::adapter::mariadb::pdo::Config;
Rust
pub struct Config

Undocumented.

use utopia_database::adapter::mariadb::pdo::Executed;
Rust
pub struct Executed

A statement's result: what execute() returned, the rows and the row count.

use utopia_database::adapter::mariadb::pdo::Pdo;
Rust
pub struct Pdo

The PDO handle: one connection.

use utopia_database::adapter::mariadb::pdo::PdoError;
Rust
pub struct PdoError

A driver error (PDOException): its SQLSTATE, the driver's native code (errorInfo[1]) and its message.

use utopia_database::adapter::mariadb::pdo::Statement;
Rust
pub struct Statement

A prepared statement: SQL with named placeholders and bound values.

use utopia_database::adapter::mariadb::pdo::ParamType;
Rust
pub enum ParamType

A PDO parameter type (PDO::PARAM_*).

use utopia_database::adapter::mariadb::pdo::PdoFailure;
Rust
pub enum PdoFailure

A failed execute(): a driver error, or another exception (a value that cannot be converted to a string).

Also implements From.
use utopia_database::adapter::mariadb::pdo::Rendering;
Rust
pub enum Rendering

Why a statement could not be rendered.

use utopia_database::adapter::mariadb::pdo::quote;
Rust
pub fn quote(s: &[u8]) -> Vec<u8>

$pdo->quote($string): the string in single quotes, escaped by mysqlnd_cset_escape_slashes for utf8mb4.

use utopia_database::adapter::mariadb::pdo::to_long;
Rust
pub fn to_long(value: &Value) -> i64

Undocumented.

adapter::mariadb::spatial

Own page

Geometries: arrays to WKT, and the SRID-prefixed WKB MariaDB and MySQL return for spatial columns (or WKT) back to coordinate arrays.

use utopia_database::adapter::mariadb::spatial::array_to_wkt;
Rust
pub fn array_to_wkt(geometry: &Array) -> Result<String>

POINT(x y), LINESTRING(...) or POLYGON((...), ...).

use utopia_database::adapter::mariadb::spatial::decode_linestring;
Rust
pub fn decode_linestring(wkb: &[u8]) -> Result<Value>

(SQL): [[x, y], ...] from WKT, or from WKB behind a 4-byte SRID.

use utopia_database::adapter::mariadb::spatial::decode_point;
Rust
pub fn decode_point(wkb: &[u8]) -> Result<Value>

(SQL): [x, y] from WKT, or from WKB behind a 4-byte SRID.

use utopia_database::adapter::mariadb::spatial::decode_polygon;
Rust
pub fn decode_polygon(wkb: &[u8]) -> Result<Value>

(SQL): [[[x, y], ...], ...] from WKT, hex or binary WKB behind a 4-byte SRID.

use utopia_database::adapter::mariadb::spatial::type_from_wkt;
Rust
pub fn type_from_wkt(wkt: &[u8]) -> Result<Vec<u8>>

The lowercase type before (.

adapter::mariadb::sql

Own page

The building blocks every statement uses: identifiers, table names, tenant conditions, column types, parameter types, and the mapping of driver errors onto the library's errors.

use utopia_database::adapter::mariadb::sql::Binds;
Rust
pub struct Binds(pub Vec<(String, Value)>)

Bound values of a statement in the making, by placeholder, in the order they were added ($binds).

use utopia_database::adapter::mariadb::sql::bind_typed;
Rust
pub fn bind_typed(stmt: &mut Statement, key: &str, value: Value) -> Result<()>

$stmt->bindValue($key, $value, $this->getPDOType($value)).

use utopia_database::adapter::mariadb::sql::filter;
Rust
pub fn filter(value: &str) -> String

Keeps [A-Za-z0-9_-].

use utopia_database::adapter::mariadb::sql::has_sequence;
Rust
pub fn has_sequence(document: &Document) -> Result<bool>

!empty($document->getSequence()).

use utopia_database::adapter::mariadb::sql::id_value;
Rust
pub fn id_value(document: &Document) -> Value

$document->getId().

use utopia_database::adapter::mariadb::sql::internal_key;
Rust
pub fn internal_key(attribute: &str) -> &str

Undocumented.

use utopia_database::adapter::mariadb::sql::interpolate;
Rust
pub fn interpolate(value: &Value) -> String

Undocumented.

use utopia_database::adapter::mariadb::sql::json_encode;
Rust
pub fn json_encode(value: &Value) -> Value

The JSON text, or false when it fails.

use utopia_database::adapter::mariadb::sql::json_text;
Rust
pub fn json_text(value: &Value) -> String

As text ("" when it fails, as interpolating false gives).

use utopia_database::adapter::mariadb::sql::pdo_type;
Rust
pub fn pdo_type(value: &Value) -> Result<ParamType>

(MariaDB): strings and floats PARAM_STR, integers and booleans PARAM_INT, null PARAM_NULL.

use utopia_database::adapter::mariadb::sql::process_exception;
Rust
pub fn process_exception(e: PdoError, mysql: bool) -> Error

(MariaDB, and MySQL's codes first when mysql): driver errors with a known SQLSTATE and code become the library's errors; others stay PDOExceptions.

use utopia_database::adapter::mariadb::sql::quote;
Rust
pub fn quote(s: &str) -> String

(MariaDB): `string`.

use utopia_database::adapter::mariadb::sql::raw;
Rust
pub fn raw(e: PdoFailure) -> Error

A failed statement as it escapes unprocessed (PDOException).

use utopia_database::adapter::mariadb::sql::row_to_document;
Rust
pub fn row_to_document(mut row: Array, find: bool) -> Result<Document>

A fetched row as a document: internal columns renamed to their $ attributes, each renamed key moving to the end, in the order getDocument() (find = false) or find() renames them.

use utopia_database::adapter::mariadb::sql::sequence;
Rust
pub fn sequence(document: &Document) -> Result<Option<Value>>

$document->getSequence(): null, or the value as a string (the return type coerces it; an array is a TypeError).

use utopia_database::adapter::mariadb::sql::spatial_attributes;
Rust
pub fn spatial_attributes(collection: &Document) -> Vec<String>

Ids of the collection's spatial attribute documents.

use utopia_database::adapter::mariadb::sql::sql_type;
Rust
pub fn sql_type(kind: &str, size: i64, signed: bool, array: bool, required: bool, mysql: bool) -> Result<String>

(MariaDB).

use utopia_database::adapter::mariadb::sql::string_attribute;
Rust
pub fn string_attribute(document: &Document, key: &str, getter: &str) -> Result<Value>

A ?string getter of a document (getCreatedAt(), getUpdatedAt()): the raw value coerced to a string.

use utopia_database::adapter::mariadb::sql::tenant_value;
Rust
pub fn tenant_value(document: &Document) -> Value

$document->getTenant().

use utopia_database::adapter::mariadb::sql::value_name;
Rust
pub fn value_name(v: &Value) -> &str

How a TypeError names a value's type.

use utopia_database::adapter::mariadb::sql::violated_key;
Rust
pub fn violated_key(message: &str) -> Option<String>

The index name of a duplicate entry error (for key 'movies._uid' is _uid), or None.

Rust
pub const MAX_VARCHAR_LENGTH: i64 = 16381

Undocumented.

adapter::memory

Own page

[Memory]: the in-memory adapter.

use utopia_database::adapter::memory::Memory;
Rust
pub struct Memory

The in-memory adapter. See the module docs.

Also implements Default.

adapter::memory::documents

Own page

Documents: reads, creates, updates, deletes, sequences, increments, the permission indexes and the unique-index hash tables.

adapter::memory::schema

Own page

Databases, collections, attributes, relationship fields and indexes.

adapter::memory::store

Own page
use utopia_database::adapter::memory::store::array_merge;
Rust
pub fn array_merge(arrays: &[&Array]) -> Array

String keys of $b overwrite in place, integer keys are renumbered after $a's.

use utopia_database::adapter::memory::store::empty;
Rust
pub fn empty(v: Option<&Value>) -> bool

Undocumented.

use utopia_database::adapter::memory::store::for_each_mut;
Rust
pub fn for_each_mut(a: &mut Array, mut f: impl FnMut(ArrayKey, &mut Value))

Undocumented.

use utopia_database::adapter::memory::store::get;
Rust
pub fn get<'a>(a: &'a Array, path: &[ArrayKey]) -> Option<&'a Value>

$a[k1][k2]... (None when a step is missing or not an array).

use utopia_database::adapter::memory::store::get_array;
Rust
pub fn get_array<'a>(a: &'a Array, path: &[ArrayKey]) -> Option<&'a Array>

$a[k1][k2]... as an array (None when missing or not an array).

use utopia_database::adapter::memory::store::isset;
Rust
pub fn isset(a: &Array, path: &[ArrayKey]) -> bool

Undocumented.

use utopia_database::adapter::memory::store::k;
Rust
pub fn k(s: &str) -> ArrayKey

An array key from text ($a['key']).

use utopia_database::adapter::memory::store::key_of;
Rust
pub fn key_of(v: &Value) -> ArrayKey

The key a value becomes as an array key ($a[$value]): integers stay, strings are normalized, null is "", booleans and floats integers.

use utopia_database::adapter::memory::store::key_value;
Rust
pub fn key_value(key: KeyRef<'_>) -> Value

A key as the value foreach ($a as $key => ...) gives.

use utopia_database::adapter::memory::store::push;
Rust
pub fn push(a: &mut Array, path: &[ArrayKey], value: Value) -> i64

$a[k1][k2]...[] = $value: the key it got.

use utopia_database::adapter::memory::store::s;
Rust
pub fn s(text: &str) -> Value

A string value.

use utopia_database::adapter::memory::store::set;
Rust
pub fn set(a: &mut Array, path: &[ArrayKey], value: Value)

$a[k1][k2]... = $value.

use utopia_database::adapter::memory::store::unset;
Rust
pub fn unset(a: &mut Array, path: &[ArrayKey])

Nothing is created on the way.

use utopia_database::adapter::memory::store::vivify;
Rust
pub fn vivify<'a>(a: &'a mut Array, path: &[ArrayKey]) -> &'a mut Array

Undocumented.

adapter::mongo

Own page

[Mongo]: the MongoDB adapter.

A collection is a MongoDB collection named <namespace>_<id> in the adapter's database; a document is a BSON document whose internal attributes are stored under _uid ($id), _id ($sequence, a UUIDv7 string), _tenant, _createdAt, _updatedAt and _permissions. Attributes need no schema: creating one is a no-op, and in schemaless mode (Adapter::set_support_for_attributes false) documents carry any attribute. Filters, sorts, cursors and permissions become a find filter; operators an aggregation pipeline update; transactions are the driver's, on a replica set.

use utopia_database::adapter::mongo::Mongo;
Rust
pub struct Mongo

The MongoDB adapter. See the module docs.

use utopia_database::adapter::mongo::from_client;
Rust
pub fn from_client(e: utopia_mongo::Error) -> Error

Undocumented.

adapter::mongo::casting

Own page

Values to and from what MongoDB stores: dates as UTCDateTime, objects as embedded documents, integers as integers.

adapter::mongo::documents

Own page

Documents: reads, creates, updates (operators as aggregation pipelines), upserts, increments, deletes, finds, counts and sums.

adapter::mongo::filters

Own page

Queries as MongoDB filters, and the key mappings between documents and stored records.

adapter::mongo::schema

Own page

Databases, collections, attributes, relationships and indexes.

adapter::pool

Own page

[Pool]: an adapter over a pool of adapters.

Every call takes a connection (an adapter) from a utopia_pools::Pool, puts it in this handle's settings (database, namespace, shared tables, tenant, authorization, timeouts, debug, metadata), runs the call on it and hands it back: reclaimed when the call succeeded, recovered (reconnected) or discarded when it failed. A transaction pins one connection for its whole body, retries included, so its statements share a session.

Timeouts are this handle's own: setting one opens no connection, and each connection is reset to them as it is checked out.

A connection whose call is cancelled (its future dropped) is destroyed, and so is a transaction's pinned connection when the handle is dropped: the pool frees their capacity rather than counting them lent forever.

use utopia_database::adapter::pool::Pool;
Rust
pub struct Pool<S = Stack<Pooled>>

An adapter over a pool of adapters. See the module docs.

Also implements Drop.
use utopia_database::adapter::pool::Pooled;
Rust
pub struct Pooled(pub Arc<dyn Adapter>)

A pooled adapter: the resource of the utopia_pools::Pool a Pool draws from.

Also implements Resource.

adapter::postgres

Own page

[Postgres]: the PostgreSQL adapter.

use utopia_database::adapter::postgres::Postgres;
Rust
pub struct Postgres

The PostgreSQL adapter. See the module docs.

adapter::postgres::ddl

Own page

Schemas, tables, columns, relationship columns and indexes.

adapter::postgres::documents

Own page

Documents: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.

adapter::postgres::find

Own page

Finds, counts and sums: WHERE conditions for every query method (comparisons, LIKE, POSIX regexes, full-text search, JSONB arrays and objects, PostGIS spatial filters), pgvector distance ordering, cursor pagination and the document-level permission filter.

adapter::postgres::operators

Own page

Operators: atomic updates as SQL expressions, and their effect on a default value for documents an upsert creates.

adapter::postgres::pdo

Own page

The adapter writes SQL with named placeholders (:_uid) and binds values with a PDO parameter type. PDO (ATTR_EMULATE_PREPARES) substitutes the placeholders client side with quoted literals and sends the statement as plain text with PQexec; with ATTR_STRINGIFY_FETCHES every fetched value is a string. Pdo reproduces that, so the server sees the same text and the adapter reads the same values:

use utopia_database::adapter::postgres::pdo::Executed;
Rust
pub struct Executed

A statement's result: what execute() returned, the rows and the row count.

use utopia_database::adapter::postgres::pdo::Pdo;
Rust
pub struct Pdo

The PDO handle: one connection.

use utopia_database::adapter::postgres::pdo::PdoError;
Rust
pub struct PdoError

A driver error (PDOException): its SQLSTATE, the driver's native code (errorInfo[1], 7 for server errors) and its message.

use utopia_database::adapter::postgres::pdo::Statement;
Rust
pub struct Statement

A prepared statement: SQL with named placeholders and bound values.

use utopia_database::adapter::postgres::pdo::ParamType;
Rust
pub enum ParamType

A PDO parameter type (PDO::PARAM_*).

use utopia_database::adapter::postgres::pdo::PdoFailure;
Rust
pub enum PdoFailure

A failed execute(): a driver error, or another exception (a value that cannot be converted to a string).

Also implements From.
use utopia_database::adapter::postgres::pdo::Rendering;
Rust
pub enum Rendering

Why a statement could not be rendered.

use utopia_database::adapter::postgres::pdo::error_of;
Rust
pub fn error_of(outcome: &Outcome, query: &[u8]) -> PdoError

The PDOException of a failed result (pdo_pgsql_error then pdo_handle_error).

use utopia_database::adapter::postgres::pdo::fetch;
Rust
pub fn fetch(oid: u32, value: Option<&Bytes>) -> Value

One fetched value (pgsql_stmt_get_col, then PDO's stringify).

use utopia_database::adapter::postgres::pdo::libpq_message;
Rust
pub fn libpq_message(outcome: &Outcome, query: &[u8]) -> String

The libpq message of an error result (PQresultErrorMessage), as pqBuildErrorMessage3 writes it with the default verbosity, for the query query it answered.

use utopia_database::adapter::postgres::pdo::quote;
Rust
pub fn quote(s: &[u8]) -> Option<Vec<u8>>

$pdo->quote($string) (PQescapeStringConn in quotes): None when the string, up to its first NUL, is not valid UTF-8.

use utopia_database::adapter::postgres::pdo::rows;
Rust
pub fn rows(outcome: &Outcome) -> Vec<Array>

The rows of a result as fetchAll(PDO::FETCH_ASSOC) returns them with ATTR_STRINGIFY_FETCHES.

use utopia_database::adapter::postgres::pdo::to_long;
Rust
pub fn to_long(value: &Value) -> i64

Undocumented.

adapter::postgres::spatial

Own page

Geometries: arrays to WKT for PostGIS, and the hex EWKB PostGIS returns (or WKT) back to coordinate arrays.

use utopia_database::adapter::postgres::spatial::array_to_wkt;
Rust
pub fn array_to_wkt(geometry: &Array) -> Result<String>

POINT(x y), LINESTRING(...) or POLYGON((...), ...).

use utopia_database::adapter::postgres::spatial::decode_linestring;
Rust
pub fn decode_linestring(wkb: &[u8]) -> Result<Value>

(Postgres): [[x, y], ...].

use utopia_database::adapter::postgres::spatial::decode_point;
Rust
pub fn decode_point(wkb: &[u8]) -> Result<Value>

(Postgres): [x, y] from WKT or hex EWKB.

use utopia_database::adapter::postgres::spatial::decode_polygon;
Rust
pub fn decode_polygon(wkb: &[u8]) -> Result<Value>

(Postgres): [[[x, y], ...], ...].

use utopia_database::adapter::postgres::spatial::type_from_wkt;
Rust
pub fn type_from_wkt(wkt: &[u8]) -> Result<Vec<u8>>

The lowercase type before (.

adapter::postgres::sql

Own page

The building blocks every statement uses: identifiers, table names, tenant conditions, column types, parameter types, statement execution with the statement timeout, and the mapping of driver errors onto the library's errors.

use utopia_database::adapter::postgres::sql::Binds;
Rust
pub struct Binds(pub Vec<(String, Value)>)

Bound values of a statement in the making, by placeholder, in the order they were added ($binds).

use utopia_database::adapter::postgres::sql::bind_typed;
Rust
pub fn bind_typed(stmt: &mut Statement, key: &str, value: Value) -> Result<()>

$stmt->bindValue($key, $value, $this->getPDOType($value)).

use utopia_database::adapter::postgres::sql::filter;
Rust
pub fn filter(value: &str) -> String

Keeps [A-Za-z0-9_-].

use utopia_database::adapter::postgres::sql::has_sequence;
Rust
pub fn has_sequence(document: &Document) -> Result<bool>

!empty($document->getSequence()).

use utopia_database::adapter::postgres::sql::id_value;
Rust
pub fn id_value(document: &Document) -> Value

$document->getId().

use utopia_database::adapter::postgres::sql::internal_key;
Rust
pub fn internal_key(attribute: &str) -> &str

Undocumented.

use utopia_database::adapter::postgres::sql::interpolate;
Rust
pub fn interpolate(value: &Value) -> String

Undocumented.

use utopia_database::adapter::postgres::sql::json_encode;
Rust
pub fn json_encode(value: &Value) -> Value

The JSON text, or false when it fails.

use utopia_database::adapter::postgres::sql::json_text;
Rust
pub fn json_text(value: &Value) -> String

As text ("" when it fails, as interpolating false gives).

use utopia_database::adapter::postgres::sql::pdo_type;
Rust
pub fn pdo_type(value: &Value) -> Result<ParamType>

Undocumented.

use utopia_database::adapter::postgres::sql::process_exception;
Rust
pub fn process_exception(e: PdoError) -> Error

(Postgres): driver errors with a known SQLSTATE become the library's errors; others stay PDOExceptions.

use utopia_database::adapter::postgres::sql::processed;
Rust
pub fn processed(e: PdoFailure) -> Error

A failed statement through processException.

use utopia_database::adapter::postgres::sql::quote;
Rust
pub fn quote(s: &str) -> String

"string".

use utopia_database::adapter::postgres::sql::raw;
Rust
pub fn raw(e: PdoFailure) -> Error

A failed statement as it escapes unprocessed (PDOException).

use utopia_database::adapter::postgres::sql::row_to_document;
Rust
pub fn row_to_document(mut row: Array, find: bool) -> Result<Document>

A fetched row as a document: internal columns renamed to their $ attributes, each renamed key moving to the end, in the order getDocument() (find = false) or find() renames them.

use utopia_database::adapter::postgres::sql::sequence;
Rust
pub fn sequence(document: &Document) -> Result<Option<Value>>

$document->getSequence(): null, or the value as a string (the return type coerces it; an array is a TypeError).

use utopia_database::adapter::postgres::sql::short_key;
Rust
pub fn short_key(key: &str) -> String

Keys longer than 63 bytes become their MD5, with the part after the last _ kept as a suffix when it fits.

use utopia_database::adapter::postgres::sql::spatial_attributes;
Rust
pub fn spatial_attributes(collection: &Document) -> Vec<String>

Ids of the collection's spatial attribute documents.

use utopia_database::adapter::postgres::sql::sql_type;
Rust
pub fn sql_type(kind: &str, size: i64, _signed: bool, array: bool, _required: bool) -> Result<String>

Undocumented.

use utopia_database::adapter::postgres::sql::string_attribute;
Rust
pub fn string_attribute(document: &Document, key: &str, getter: &str) -> Result<Value>

A ?string getter of a document (getCreatedAt(), getUpdatedAt()): the raw value coerced to a string.

use utopia_database::adapter::postgres::sql::tenant_value;
Rust
pub fn tenant_value(document: &Document) -> Value

$document->getTenant().

use utopia_database::adapter::postgres::sql::value_name;
Rust
pub fn value_name(v: &Value) -> &str

How a TypeError names a value's type.

use utopia_database::adapter::postgres::sql::violated_columns;
Rust
pub fn violated_columns(message: &str) -> Option<Vec<String>>

The sorted columns of Key (a, b)=(...), or None when the message has none.

Rust
pub const MAX_IDENTIFIER_NAME: usize = 63

Postgres::MAX_IDENTIFIER_NAME.

Rust
pub const MAX_VARCHAR_LENGTH: i64 = 16381

Undocumented.

adapter::postgres::widths

Own page

Display widths of Unicode characters, as libpq computes them for the caret under an error position (ucs_wcwidth in PostgreSQL 18's src/common/wchar.c, over the tables PostgreSQL generates from Unicode).

Rust
pub const EAST_ASIAN_FW: &[(u32, u32)] = &[ (0x1100, 0x115F), (0x231A, 0x231B), (0x2329, 0x232A), (0x23E9, 0x23EC), (0x23F0, 0x23F0), (0x23F3, 0x23F3), (0x25FD, 0x25FE), (0x2614, 0x2615), (0x2630, 0x2637), (0x2648, 0x2653), (0x267F, 0x267F), (0x268A, 0x268F), (0x2693, 0x2693), (0x26A1, 0x26A1), (0x26AA, 0x26AB), (0x26BD, 0x26BE), (0x26C4, 0x26C5), (0x26CE, 0x26CE), (0x26D4, 0x26D4), (0x26EA, 0x26EA), (0x26F2, 0x26F3), (0x26F5, 0x26F5), (0x26FA, 0x26FA), (0x26FD, 0x26FD), (0x2705, 0x2705), (0x270A, 0x270B), (0x2728, 0x2728), (0x274C, 0x274C), (0x274E, 0x274E),

East Asian wide and fullwidth characters (width 2): unicode_east_asian_fw_table.h.

Rust
pub const NONSPACING: &[(u32, u32)] = &[ (0x00AD, 0x00AD), (0x0300, 0x036F), (0x0483, 0x0489), (0x0591, 0x05BD), (0x05BF, 0x05BF), (0x05C1, 0x05C2), (0x05C4, 0x05C5), (0x05C7, 0x05C7), (0x0600, 0x0605), (0x0610, 0x061A), (0x061C, 0x061C), (0x064B, 0x065F), (0x0670, 0x0670), (0x06D6, 0x06DD), (0x06DF, 0x06E4), (0x06E7, 0x06E8), (0x06EA, 0x06ED), (0x070F, 0x070F), (0x0711, 0x0711), (0x0730, 0x074A), (0x07A6, 0x07B0), (0x07EB, 0x07F3), (0x07FD, 0x07FD), (0x0816, 0x0819), (0x081B, 0x0823), (0x0825, 0x0827), (0x0829, 0x082D), (0x0859, 0x085B), (0x0890, 0x089F),

Non-spacing characters (width 0): unicode_nonspacing_table.h.

adapter::postgres::wire

Own page

The PostgreSQL frontend/backend protocol, as libpq's PQexec speaks it.

Wire is one server connection: it authenticates (trust, cleartext, MD5 or SCRAM-SHA-256), then runs statements with the simple query protocol, keeping the transaction status every ReadyForQuery reports. Statements are bytes, sent as-is up to their first NUL (a C string, as libpq sends them), and results keep the bytes the server sent, with the type of each column, so the adapter can read rows exactly as PDO's pgsql driver does.

use utopia_database::adapter::postgres::wire::Column;
Rust
pub struct Column

A column of a result: its name and type OID.

use utopia_database::adapter::postgres::wire::Config;
Rust
pub struct Config

Where and as whom to connect.

use utopia_database::adapter::postgres::wire::Outcome;
Rust
pub struct Outcome

One result (PGresult): the last of a query string, as PQexec keeps.

use utopia_database::adapter::postgres::wire::Wire;
Rust
pub struct Wire

A server connection.

use utopia_database::adapter::postgres::wire::Status;
Rust
pub enum Status

What PQresultStatus() reports for a result.

use utopia_database::adapter::postgres::wire::TxStatus;
Rust
pub enum TxStatus

PQtransactionStatus().

adapter::redis

Own page

[Redis]: documents stored in Redis.

Every key starts with utopia:{namespace}:{database}:

KeyTypeHolds
utopia:{ns}:dbsSETdatabase names (per namespace)
…:colsSETcollection ids of the database
…:meta:{col}HASHschema, attrs, indexes, docCount, sizeBytes
…:doc:{col}:{id}STRINGthe document as JSON
…:idx:{col}SETthe ids of the collection's documents
…:seq:{col}STRINGthe last $sequence given
…:perm:{col}:{r|c|u|d|w}:{role}SETids a role may act on
…:perm:doc:{col}:{id}HASHrole => its action letters
use utopia_database::adapter::redis::Redis;
Rust
pub struct Redis

The Redis adapter. See the module docs.

Rust
pub const KEY_PREFIX: &str = "utopia"

The prefix of every key (KEY_PREFIX).

Rust
pub const SEP: &str = ":"

The separator of key segments (SEP).

adapter::redis::documents

Own page

Documents of the Redis adapter: reads, writes, bulk writes, upserts, sequences, deletes and increments, journalled inside transactions.

adapter::redis::operators

Own page

Operators of the Redis adapter: applied here to the stored value, as the SQL adapters apply them in SQL.

adapter::redis::schema

Own page

Databases, collections, attributes, indexes and relationships of the Redis adapter: the meta hash of each collection and the scans that rewrite or drop its keys.

adapter::sqlite

Own page

[Sqlite]: the SQLite adapter.

use utopia_database::adapter::sqlite::Sqlite;
Rust
pub struct Sqlite

The SQLite adapter. See the module docs.

adapter::sqlite::ddl

Own page

Tables, columns, relationship columns, indexes (FTS5 virtual tables for fulltext ones) and schema introspection.

adapter::sqlite::documents

Own page

Documents: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.

adapter::sqlite::find

Own page

Finds, counts and sums: WHERE conditions for every query method (comparisons, LIKE with explicit escapes, REGEXP, FTS5 searches, JSON array membership), cursor pagination and the document-level permission filter.

adapter::sqlite::operators

Own page

Operators: atomic updates as SQL expressions (SQLite's JSON functions for arrays), and their effect on a default value for documents an upsert creates.

adapter::sqlite::pdo

Own page

The adapter writes SQL with named placeholders (:_uid) and binds values with a PDO parameter type. The sqlite driver prepares the statement as it is (sqlite3_prepare_v2: SQLite reads :name placeholders itself, and text after the first statement is ignored) and binds each value when the statement executes, so Pdo does the same over rusqlite:

use utopia_database::adapter::sqlite::pdo::Executed;
Rust
pub struct Executed

A statement's result: what execute() returned, the rows and the row count.

use utopia_database::adapter::sqlite::pdo::Pdo;
Rust
pub struct Pdo

The PDO handle: one SQLite database file.

use utopia_database::adapter::sqlite::pdo::PdoError;
Rust
pub struct PdoError

A driver error (PDOException): its SQLSTATE, SQLite's result code (errorInfo[1]) and its message.

use utopia_database::adapter::sqlite::pdo::Statement;
Rust
pub struct Statement

A prepared statement: SQL with named placeholders and bound values.

use utopia_database::adapter::sqlite::pdo::ParamType;
Rust
pub enum ParamType

A PDO parameter type (PDO::PARAM_*).

use utopia_database::adapter::sqlite::pdo::PdoFailure;
Rust
pub enum PdoFailure

A failed execute(): a driver error, or another exception (a value that cannot be converted to a string).

Also implements From.
use utopia_database::adapter::sqlite::pdo::to_long;
Rust
pub fn to_long(value: &Value) -> i64

Undocumented.

adapter::sqlite::sql

Own page

The building blocks every statement uses: identifiers, table names, tenant conditions, column types, parameter types, statement execution, the mapping of driver errors onto the library's errors, and geometry text.

use utopia_database::adapter::sqlite::sql::Binds;
Rust
pub struct Binds(pub Vec<(String, Value)>)

Bound values of a statement in the making, by placeholder, in the order they were added ($binds).

use utopia_database::adapter::sqlite::sql::array_to_wkt;
Rust
pub fn array_to_wkt(geometry: &Array) -> Result<String>

POINT(x y), LINESTRING(...) or POLYGON((...), ...).

use utopia_database::adapter::sqlite::sql::bind_typed;
Rust
pub fn bind_typed(stmt: &mut Statement, key: &str, value: Value) -> Result<()>

$stmt->bindValue($key, $value, $this->getPDOType($value)).

use utopia_database::adapter::sqlite::sql::decode_linestring;
Rust
pub fn decode_linestring(wkb: &[u8]) -> Result<Value>

(SQL): [[x, y], ...].

use utopia_database::adapter::sqlite::sql::decode_point;
Rust
pub fn decode_point(wkb: &[u8]) -> Result<Value>

(SQL): [x, y] from WKT or SRID-prefixed WKB.

use utopia_database::adapter::sqlite::sql::decode_polygon;
Rust
pub fn decode_polygon(wkb: &[u8]) -> Result<Value>

(SQL): [[[x, y], ...], ...].

use utopia_database::adapter::sqlite::sql::filter;
Rust
pub fn filter(value: &str) -> String

Keeps [A-Za-z0-9_-].

use utopia_database::adapter::sqlite::sql::has_sequence;
Rust
pub fn has_sequence(document: &Document) -> Result<bool>

!empty($document->getSequence()).

use utopia_database::adapter::sqlite::sql::id_value;
Rust
pub fn id_value(document: &Document) -> Value

$document->getId().

use utopia_database::adapter::sqlite::sql::internal_key;
Rust
pub fn internal_key(attribute: &str) -> &str

Undocumented.

use utopia_database::adapter::sqlite::sql::interpolate;
Rust
pub fn interpolate(value: &Value) -> String

Undocumented.

use utopia_database::adapter::sqlite::sql::json_encode;
Rust
pub fn json_encode(value: &Value) -> Value

The JSON text, or false when it fails.

use utopia_database::adapter::sqlite::sql::json_text;
Rust
pub fn json_text(value: &Value) -> String

As text ("" when it fails, as interpolating false gives).

use utopia_database::adapter::sqlite::sql::pdo_type;
Rust
pub fn pdo_type(value: &Value) -> Result<ParamType>

(MariaDB): strings and floats bind as strings, integers and booleans as integers.

use utopia_database::adapter::sqlite::sql::process_exception;
Rust
pub fn process_exception(e: PdoError) -> Error

(SQLite): driver errors SQLite reports for existing and missing tables, unique violations and oversized values become the library's errors; others stay PDOExceptions.

use utopia_database::adapter::sqlite::sql::processed;
Rust
pub fn processed(e: PdoFailure) -> Error

A failed statement through processException.

use utopia_database::adapter::sqlite::sql::quote;
Rust
pub fn quote(s: &str) -> String

(MariaDB): `string`.

use utopia_database::adapter::sqlite::sql::raw;
Rust
pub fn raw(e: PdoFailure) -> Error

A failed statement as it escapes unprocessed (PDOException).

use utopia_database::adapter::sqlite::sql::row_to_document;
Rust
pub fn row_to_document(mut row: Array, find: bool) -> Result<Document>

A fetched row as a document: internal columns renamed to their $ attributes, each renamed key moving to the end, in the order getDocument() (find = false) or find() renames them.

use utopia_database::adapter::sqlite::sql::sequence;
Rust
pub fn sequence(document: &Document) -> Result<Option<Value>>

$document->getSequence(): null, or the value as a string (the return type coerces it; an array is a TypeError).

use utopia_database::adapter::sqlite::sql::spatial_attributes;
Rust
pub fn spatial_attributes(collection: &Document) -> Vec<String>

Ids of the collection's spatial attribute documents.

use utopia_database::adapter::sqlite::sql::sql_type;
Rust
pub fn sql_type(kind: &str, size: i64, signed: bool, array: bool, required: bool) -> Result<String>

(MariaDB).

use utopia_database::adapter::sqlite::sql::string_attribute;
Rust
pub fn string_attribute(document: &Document, key: &str, getter: &str) -> Result<Value>

A ?string getter of a document (getCreatedAt(), getUpdatedAt()): the raw value coerced to a string.

use utopia_database::adapter::sqlite::sql::tenant_value;
Rust
pub fn tenant_value(document: &Document) -> Value

$document->getTenant().

use utopia_database::adapter::sqlite::sql::type_from_wkt;
Rust
pub fn type_from_wkt(wkt: &[u8]) -> Result<Vec<u8>>

The lowercase type before (.

use utopia_database::adapter::sqlite::sql::violated_columns;
Rust
pub fn violated_columns(message: &str) -> Option<Vec<String>>

(SQLite): the sorted columns of UNIQUE constraint failed: t.a, t.b, or None when the message has none.

Rust
pub const MAX_VARCHAR_LENGTH: i64 = 16381

Undocumented.

adapter::sqlstate

Own page

The descriptions PDO gives SQLSTATEs in its exception messages (SQLSTATE[23000]: Integrity constraint violation: ...), the same for every PDO driver.

use utopia_database::adapter::sqlstate::describe;
Rust
pub fn describe(sqlstate: &str) -> &'static str

The description PDO gives a SQLSTATE (pdo_sqlstate_state_to_description).