mariadb
Module[MariaDB]: the MariaDB adapter, and with Flavor::MySQL (feature
mysql) the MySQL adapter.
use utopia_database::Adapter;
use utopia_database::adapter::mariadb::MariaDB;
let adapter = MariaDB::connect("mysql://root:password@localhost:3306").await?;
adapter.set_database("appwrite")?;
adapter.set_namespace("_1")?;
adapter.create("appwrite").await?;Contents
7 submodules, and what the module defines itself.
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.
mariadb::ddl
Own pageDatabases, tables, columns, relationship columns and indexes, and the schema as the server reports it.
mariadb::documents
Own pageDocuments: reads by id, creates, updates, upserts, deletes, sequence lookups and atomic increments, with their permission rows.
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.
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.
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.
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 (.
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.