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;pub struct FindOptions<'a>The arguments of Adapter::find besides the collection and queries.
use utopia_database::adapter::State;pub struct StateUndocumented.
Default.use utopia_database::adapter::StateInner;pub struct StateInnerThe fields of State.
use utopia_database::Adapter;pub trait Adapter: Send + SyncA storage engine. See the module docs.
use utopia_database::adapter::with_transaction;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.
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.
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;pub struct MariaDBThe MariaDB (or MySQL) adapter. See the module docs.
use utopia_database::adapter::mariadb::Flavor;pub enum FlavorUndocumented.
adapter::mariadb::ddl
Own pageDatabases, tables, columns, relationship columns and indexes, and the schema as the server reports it.
adapter::mariadb::documents
Own pageDocuments: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.
adapter::mariadb::find
Own pageFinds, 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 pageOperators: 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 pageThe 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;pub struct ConfigUndocumented.
use utopia_database::adapter::mariadb::pdo::Executed;pub struct ExecutedA statement's result: what execute() returned, the rows and the row count.
use utopia_database::adapter::mariadb::pdo::Pdo;pub struct PdoThe PDO handle: one connection.
use utopia_database::adapter::mariadb::pdo::PdoError;pub struct PdoErrorA driver error (PDOException): its SQLSTATE, the driver's native code
(errorInfo[1]) and its message.
use utopia_database::adapter::mariadb::pdo::Statement;pub struct StatementA prepared statement: SQL with named placeholders and bound values.
use utopia_database::adapter::mariadb::pdo::ParamType;pub enum ParamTypeA PDO parameter type (PDO::PARAM_*).
use utopia_database::adapter::mariadb::pdo::PdoFailure;pub enum PdoFailureA failed execute(): a driver error, or another exception (a value
that cannot be converted to a string).
From.use utopia_database::adapter::mariadb::pdo::Rendering;pub enum RenderingWhy a statement could not be rendered.
use utopia_database::adapter::mariadb::pdo::quote;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;pub fn to_long(value: &Value) -> i64Undocumented.
adapter::mariadb::spatial
Own pageGeometries: 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;pub fn array_to_wkt(geometry: &Array) -> Result<String>POINT(x y), LINESTRING(...) or
POLYGON((...), ...).
use utopia_database::adapter::mariadb::spatial::decode_linestring;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;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;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;pub fn type_from_wkt(wkt: &[u8]) -> Result<Vec<u8>>The lowercase type before (.
adapter::mariadb::sql
Own pageThe 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;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;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;pub fn filter(value: &str) -> StringKeeps [A-Za-z0-9_-].
use utopia_database::adapter::mariadb::sql::has_sequence;pub fn has_sequence(document: &Document) -> Result<bool>!empty($document->getSequence()).
use utopia_database::adapter::mariadb::sql::id_value;pub fn id_value(document: &Document) -> Value$document->getId().
use utopia_database::adapter::mariadb::sql::internal_key;pub fn internal_key(attribute: &str) -> &strUndocumented.
use utopia_database::adapter::mariadb::sql::interpolate;pub fn interpolate(value: &Value) -> StringUndocumented.
use utopia_database::adapter::mariadb::sql::json_encode;pub fn json_encode(value: &Value) -> ValueThe JSON text, or false when it fails.
use utopia_database::adapter::mariadb::sql::json_text;pub fn json_text(value: &Value) -> StringAs text ("" when it fails, as interpolating
false gives).
use utopia_database::adapter::mariadb::sql::pdo_type;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;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;pub fn quote(s: &str) -> String(MariaDB): `string`.
use utopia_database::adapter::mariadb::sql::raw;pub fn raw(e: PdoFailure) -> ErrorA failed statement as it escapes unprocessed (PDOException).
use utopia_database::adapter::mariadb::sql::row_to_document;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;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;pub fn spatial_attributes(collection: &Document) -> Vec<String>Ids of the collection's spatial attribute documents.
use utopia_database::adapter::mariadb::sql::sql_type;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;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;pub fn tenant_value(document: &Document) -> Value$document->getTenant().
use utopia_database::adapter::mariadb::sql::value_name;pub fn value_name(v: &Value) -> &strHow a TypeError names a value's type.
use utopia_database::adapter::mariadb::sql::violated_key;pub fn violated_key(message: &str) -> Option<String>The index name of a duplicate entry error
(for key 'movies._uid' is _uid), or None.
pub const MAX_VARCHAR_LENGTH: i64 = 16381Undocumented.
adapter::memory
Own page[Memory]: the in-memory adapter.
use utopia_database::adapter::memory::Memory;pub struct MemoryThe in-memory adapter. See the module docs.
Default.adapter::memory::documents
Own pageDocuments: reads, creates, updates, deletes, sequences, increments, the permission indexes and the unique-index hash tables.
adapter::memory::schema
Own pageDatabases, collections, attributes, relationship fields and indexes.
adapter::memory::store
Own pageuse utopia_database::adapter::memory::store::array_merge;pub fn array_merge(arrays: &[&Array]) -> ArrayString keys of $b overwrite in place, integer
keys are renumbered after $a's.
use utopia_database::adapter::memory::store::empty;pub fn empty(v: Option<&Value>) -> boolUndocumented.
use utopia_database::adapter::memory::store::for_each_mut;pub fn for_each_mut(a: &mut Array, mut f: impl FnMut(ArrayKey, &mut Value))Undocumented.
use utopia_database::adapter::memory::store::get;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;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;pub fn isset(a: &Array, path: &[ArrayKey]) -> boolUndocumented.
use utopia_database::adapter::memory::store::k;pub fn k(s: &str) -> ArrayKeyAn array key from text ($a['key']).
use utopia_database::adapter::memory::store::key_of;pub fn key_of(v: &Value) -> ArrayKeyThe 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;pub fn key_value(key: KeyRef<'_>) -> ValueA key as the value foreach ($a as $key => ...) gives.
use utopia_database::adapter::memory::store::push;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;pub fn s(text: &str) -> ValueA string value.
use utopia_database::adapter::memory::store::set;pub fn set(a: &mut Array, path: &[ArrayKey], value: Value)$a[k1][k2]... = $value.
use utopia_database::adapter::memory::store::unset;pub fn unset(a: &mut Array, path: &[ArrayKey])Nothing is created on the way.
use utopia_database::adapter::memory::store::vivify;pub fn vivify<'a>(a: &'a mut Array, path: &[ArrayKey]) -> &'a mut ArrayUndocumented.
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;pub struct MongoThe MongoDB adapter. See the module docs.
use utopia_database::adapter::mongo::from_client;pub fn from_client(e: utopia_mongo::Error) -> ErrorUndocumented.
adapter::mongo::casting
Own pageValues to and from what MongoDB stores: dates as UTCDateTime,
objects as embedded documents, integers as integers.
adapter::mongo::documents
Own pageDocuments: reads, creates, updates (operators as aggregation pipelines), upserts, increments, deletes, finds, counts and sums.
adapter::mongo::filters
Own pageQueries as MongoDB filters, and the key mappings between documents and stored records.
adapter::mongo::schema
Own pageDatabases, 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;pub struct Pool<S = Stack<Pooled>>An adapter over a pool of adapters. See the module docs.
Drop.use utopia_database::adapter::pool::Pooled;pub struct Pooled(pub Arc<dyn Adapter>)A pooled adapter: the resource of the utopia_pools::Pool a Pool
draws from.
Resource.adapter::postgres
Own page[Postgres]: the PostgreSQL adapter.
use utopia_database::adapter::postgres::Postgres;pub struct PostgresThe PostgreSQL adapter. See the module docs.
adapter::postgres::ddl
Own pageSchemas, tables, columns, relationship columns and indexes.
adapter::postgres::documents
Own pageDocuments: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.
adapter::postgres::find
Own pageFinds, 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 pageOperators: atomic updates as SQL expressions, and their effect on a default value for documents an upsert creates.
adapter::postgres::pdo
Own pageThe 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;pub struct ExecutedA statement's result: what execute() returned, the rows and the row count.
use utopia_database::adapter::postgres::pdo::Pdo;pub struct PdoThe PDO handle: one connection.
use utopia_database::adapter::postgres::pdo::PdoError;pub struct PdoErrorA 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;pub struct StatementA prepared statement: SQL with named placeholders and bound values.
use utopia_database::adapter::postgres::pdo::ParamType;pub enum ParamTypeA PDO parameter type (PDO::PARAM_*).
use utopia_database::adapter::postgres::pdo::PdoFailure;pub enum PdoFailureA failed execute(): a driver error, or another exception (a value
that cannot be converted to a string).
From.use utopia_database::adapter::postgres::pdo::Rendering;pub enum RenderingWhy a statement could not be rendered.
use utopia_database::adapter::postgres::pdo::error_of;pub fn error_of(outcome: &Outcome, query: &[u8]) -> PdoErrorThe PDOException of a failed result (pdo_pgsql_error then
pdo_handle_error).
use utopia_database::adapter::postgres::pdo::fetch;pub fn fetch(oid: u32, value: Option<&Bytes>) -> ValueOne fetched value (pgsql_stmt_get_col, then PDO's stringify).
use utopia_database::adapter::postgres::pdo::libpq_message;pub fn libpq_message(outcome: &Outcome, query: &[u8]) -> StringThe 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;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;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;pub fn to_long(value: &Value) -> i64Undocumented.
adapter::postgres::spatial
Own pageGeometries: 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;pub fn array_to_wkt(geometry: &Array) -> Result<String>POINT(x y), LINESTRING(...) or
POLYGON((...), ...).
use utopia_database::adapter::postgres::spatial::decode_linestring;pub fn decode_linestring(wkb: &[u8]) -> Result<Value>(Postgres): [[x, y], ...].
use utopia_database::adapter::postgres::spatial::decode_point;pub fn decode_point(wkb: &[u8]) -> Result<Value>(Postgres): [x, y] from WKT or hex EWKB.
use utopia_database::adapter::postgres::spatial::decode_polygon;pub fn decode_polygon(wkb: &[u8]) -> Result<Value>(Postgres): [[[x, y], ...], ...].
use utopia_database::adapter::postgres::spatial::type_from_wkt;pub fn type_from_wkt(wkt: &[u8]) -> Result<Vec<u8>>The lowercase type before (.
adapter::postgres::sql
Own pageThe 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;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;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;pub fn filter(value: &str) -> StringKeeps [A-Za-z0-9_-].
use utopia_database::adapter::postgres::sql::has_sequence;pub fn has_sequence(document: &Document) -> Result<bool>!empty($document->getSequence()).
use utopia_database::adapter::postgres::sql::id_value;pub fn id_value(document: &Document) -> Value$document->getId().
use utopia_database::adapter::postgres::sql::internal_key;pub fn internal_key(attribute: &str) -> &strUndocumented.
use utopia_database::adapter::postgres::sql::interpolate;pub fn interpolate(value: &Value) -> StringUndocumented.
use utopia_database::adapter::postgres::sql::json_encode;pub fn json_encode(value: &Value) -> ValueThe JSON text, or false when it fails.
use utopia_database::adapter::postgres::sql::json_text;pub fn json_text(value: &Value) -> StringAs text ("" when it fails, as interpolating
false gives).
use utopia_database::adapter::postgres::sql::pdo_type;pub fn pdo_type(value: &Value) -> Result<ParamType>Undocumented.
use utopia_database::adapter::postgres::sql::process_exception;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;pub fn processed(e: PdoFailure) -> ErrorA failed statement through processException.
use utopia_database::adapter::postgres::sql::quote;pub fn quote(s: &str) -> String"string".
use utopia_database::adapter::postgres::sql::raw;pub fn raw(e: PdoFailure) -> ErrorA failed statement as it escapes unprocessed (PDOException).
use utopia_database::adapter::postgres::sql::row_to_document;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;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;pub fn short_key(key: &str) -> StringKeys 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;pub fn spatial_attributes(collection: &Document) -> Vec<String>Ids of the collection's spatial attribute documents.
use utopia_database::adapter::postgres::sql::sql_type;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;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;pub fn tenant_value(document: &Document) -> Value$document->getTenant().
use utopia_database::adapter::postgres::sql::value_name;pub fn value_name(v: &Value) -> &strHow a TypeError names a value's type.
use utopia_database::adapter::postgres::sql::violated_columns;pub fn violated_columns(message: &str) -> Option<Vec<String>>The sorted columns of
Key (a, b)=(...), or None when the message has none.
pub const MAX_IDENTIFIER_NAME: usize = 63Postgres::MAX_IDENTIFIER_NAME.
pub const MAX_VARCHAR_LENGTH: i64 = 16381Undocumented.
adapter::postgres::widths
Own pageDisplay 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).
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.
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 pageThe 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;pub struct ColumnA column of a result: its name and type OID.
use utopia_database::adapter::postgres::wire::Config;pub struct ConfigWhere and as whom to connect.
use utopia_database::adapter::postgres::wire::Outcome;pub struct OutcomeOne result (PGresult): the last of a query string, as PQexec keeps.
use utopia_database::adapter::postgres::wire::Wire;pub struct WireA server connection.
use utopia_database::adapter::postgres::wire::Status;pub enum StatusWhat PQresultStatus() reports for a result.
use utopia_database::adapter::postgres::wire::TxStatus;pub enum TxStatusPQtransactionStatus().
adapter::redis
Own page[Redis]: documents stored in Redis.
Every key starts with utopia:{namespace}:{database}:
| Key | Type | Holds |
|---|---|---|
utopia:{ns}:dbs | SET | database names (per namespace) |
…:cols | SET | collection ids of the database |
…:meta:{col} | HASH | schema, attrs, indexes, docCount, sizeBytes |
…:doc:{col}:{id} | STRING | the document as JSON |
…:idx:{col} | SET | the ids of the collection's documents |
…:seq:{col} | STRING | the last $sequence given |
…:perm:{col}:{r|c|u|d|w}:{role} | SET | ids a role may act on |
…:perm:doc:{col}:{id} | HASH | role => its action letters |
use utopia_database::adapter::redis::Redis;pub struct RedisThe Redis adapter. See the module docs.
pub const KEY_PREFIX: &str = "utopia"The prefix of every key (KEY_PREFIX).
pub const SEP: &str = ":"The separator of key segments (SEP).
adapter::sqlite
Own page[Sqlite]: the SQLite adapter.
use utopia_database::adapter::sqlite::Sqlite;pub struct SqliteThe SQLite adapter. See the module docs.
adapter::sqlite::ddl
Own pageTables, columns, relationship columns, indexes (FTS5 virtual tables for fulltext ones) and schema introspection.
adapter::sqlite::documents
Own pageDocuments: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.
adapter::sqlite::find
Own pageFinds, 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 pageOperators: 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 pageThe 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;pub struct ExecutedA statement's result: what execute() returned, the rows and the row count.
use utopia_database::adapter::sqlite::pdo::Pdo;pub struct PdoThe PDO handle: one SQLite database file.
use utopia_database::adapter::sqlite::pdo::PdoError;pub struct PdoErrorA driver error (PDOException): its SQLSTATE, SQLite's result code
(errorInfo[1]) and its message.
use utopia_database::adapter::sqlite::pdo::Statement;pub struct StatementA prepared statement: SQL with named placeholders and bound values.
use utopia_database::adapter::sqlite::pdo::ParamType;pub enum ParamTypeA PDO parameter type (PDO::PARAM_*).
use utopia_database::adapter::sqlite::pdo::PdoFailure;pub enum PdoFailureA failed execute(): a driver error, or another exception (a value
that cannot be converted to a string).
From.use utopia_database::adapter::sqlite::pdo::to_long;pub fn to_long(value: &Value) -> i64Undocumented.
adapter::sqlite::sql
Own pageThe 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;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;pub fn array_to_wkt(geometry: &Array) -> Result<String>POINT(x y), LINESTRING(...) or
POLYGON((...), ...).
use utopia_database::adapter::sqlite::sql::bind_typed;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;pub fn decode_linestring(wkb: &[u8]) -> Result<Value>(SQL): [[x, y], ...].
use utopia_database::adapter::sqlite::sql::decode_point;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;pub fn decode_polygon(wkb: &[u8]) -> Result<Value>(SQL): [[[x, y], ...], ...].
use utopia_database::adapter::sqlite::sql::filter;pub fn filter(value: &str) -> StringKeeps [A-Za-z0-9_-].
use utopia_database::adapter::sqlite::sql::has_sequence;pub fn has_sequence(document: &Document) -> Result<bool>!empty($document->getSequence()).
use utopia_database::adapter::sqlite::sql::id_value;pub fn id_value(document: &Document) -> Value$document->getId().
use utopia_database::adapter::sqlite::sql::internal_key;pub fn internal_key(attribute: &str) -> &strUndocumented.
use utopia_database::adapter::sqlite::sql::interpolate;pub fn interpolate(value: &Value) -> StringUndocumented.
use utopia_database::adapter::sqlite::sql::json_encode;pub fn json_encode(value: &Value) -> ValueThe JSON text, or false when it fails.
use utopia_database::adapter::sqlite::sql::json_text;pub fn json_text(value: &Value) -> StringAs text ("" when it fails, as interpolating
false gives).
use utopia_database::adapter::sqlite::sql::pdo_type;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;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;pub fn processed(e: PdoFailure) -> ErrorA failed statement through processException.
use utopia_database::adapter::sqlite::sql::quote;pub fn quote(s: &str) -> String(MariaDB): `string`.
use utopia_database::adapter::sqlite::sql::raw;pub fn raw(e: PdoFailure) -> ErrorA failed statement as it escapes unprocessed (PDOException).
use utopia_database::adapter::sqlite::sql::row_to_document;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;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;pub fn spatial_attributes(collection: &Document) -> Vec<String>Ids of the collection's spatial attribute documents.
use utopia_database::adapter::sqlite::sql::sql_type;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;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;pub fn tenant_value(document: &Document) -> Value$document->getTenant().
use utopia_database::adapter::sqlite::sql::type_from_wkt;pub fn type_from_wkt(wkt: &[u8]) -> Result<Vec<u8>>The lowercase type before (.
use utopia_database::adapter::sqlite::sql::violated_columns;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.
pub const MAX_VARCHAR_LENGTH: i64 = 16381Undocumented.
adapter::sqlstate
Own pageThe 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;pub fn describe(sqlstate: &str) -> &'static strThe description PDO gives a SQLSTATE (pdo_sqlstate_state_to_description).