Modules
Contents
use utopia_query::Code;pub struct Code(pub i64);An exception code: an integer, or a string PHP turns into one (a numeric
string is cast, anything else is 0).
From<i64>, From<&str>, Display.use utopia_query::ParsedQuery;pub struct ParsedQuery {
pub filters: Vec<Query>,
pub selections: Vec<Query>,
pub aggregations: Vec<Query>,
pub group_by: Vec<Value>,
pub having: Vec<Query>,
pub distinct: bool,
pub joins: Vec<Query>,
pub unions: Vec<Query>,
pub limit: Option<i64>,
pub offset: Option<i64>,
pub cursor: Option<Value>,
pub cursor_direction: Option<CursorDirection>,
pub time_buckets: Vec<TimeBucket>,
}The queries grouped by what they do, as builders compile them.
PHP: Utopia\Query\Builder\ParsedQuery.
use utopia_query::Query;pub struct Query {
// private fields
}One query: a Method, the attribute it applies to, its values, and the
alias a join or an aggregate is exposed under.
Values are PHP values (Value); nested queries (the children of and,
or, having, the conditions of a join) are values too.
PHP: Utopia\Query\Query.
use utopia_query::{Method, Query};
let query = Query::equal("status", ["active", "pending"]);
assert_eq!(query.method(), Method::Equal);
assert_eq!(query.to_string()?, r#"{"method":"equal","attribute":"status","values":["active","pending"]}"#);use Utopia\Query\Query;
$query = Query::equal('status', ['active', 'pending']);
echo $query->getMethod()->value, "\n"; // equal
echo $query->toString(), "\n"; // {"method":"equal","attribute":"status","values":["active","pending"]}From<Query>.use utopia_query::TimeBucket;pub struct TimeBucket {
pub attribute: String,
pub interval: Value,
}A groupByTimeBucket query: the attribute and the bucket size.
use utopia_query::CursorDirection;pub enum CursorDirection {
After,
Before,
}Which side of a cursor row a page is on.
PHP: Utopia\Query\CursorDirection.
Display.use utopia_query::Error;pub enum Error {
Query {
message: String,
code: i64,
previous: Option<Arc<dyn Error + Send + Sync>>,
raw: Option<Arc<[u8]>>,
},
Validation(String),
Unsupported(String),
InvalidArgument(String),
InvalidValue(String),
Type(String),
NoExecutor(String),
Engine(String),
Json {
message: String,
code: i64,
},
}Why a query could not be parsed, validated or compiled.
PHP: one variant per exception class the library throws, with the same
message (Error::php_class names the class).
PartialEq.use utopia_query::Method;pub enum Method {
Equal,
NotEqual,
LessThan,
LessThanEqual,
GreaterThan,
GreaterThanEqual,
Contains,
ContainsAny,
NotContains,
Search,
NotSearch,
IsNull,
IsNotNull,
Between,
NotBetween,
StartsWith,
NotStartsWith,
EndsWith,
NotEndsWith,
Regex,
Exists,
NotExists,
Crosses,
NotCrosses,
DistanceEqual,
DistanceNotEqual,
DistanceGreaterThan,
DistanceLessThan,
Intersects,
NotIntersects,
Overlaps,
NotOverlaps,
Touches,
NotTouches,
VectorDot,
VectorCosine,
VectorEuclidean,
Select,
OrderDesc,
OrderAsc,
OrderRandom,
Limit,
Offset,
CursorAfter,
CursorBefore,
And,
Or,
ContainsAll,
ElemMatch,
Relationship,
Count,
CountDistinct,
Sum,
Avg,
Min,
Max,
Stddev,
StddevPop,
StddevSamp,
Variance,
VarPop,
VarSamp,
BitAnd,
BitOr,
BitXor,
GroupBy,
GroupByTimeBucket,
Having,
Distinct,
Join,
LeftJoin,
RightJoin,
CrossJoin,
FullOuterJoin,
NaturalJoin,
On,
Union,
UnionAll,
JsonContains,
JsonNotContains,
JsonOverlaps,
JsonPath,
OrderVectorDistance,
Covers,
NotCovers,
SpatialEquals,
NotSpatialEquals,
Raw,
}What a Query does: filter, order, paginate, select,
aggregate, join, combine, or carry raw SQL.
PHP: Utopia\Query\Method.
Display.use utopia_query::NullsPosition;pub enum NullsPosition {
First,
Last,
}Where NULLs sort.
PHP: Utopia\Query\NullsPosition.
Display, From<NullsPosition>.use utopia_query::Object;pub enum Object {
Query(Box<Query>),
Nulls(NullsPosition),
Row {
class: String,
fields: Array,
},
}An object among a query's values.
From<NullsPosition>, Extension.use utopia_query::OrderDirection;pub enum OrderDirection {
Asc,
Desc,
Random,
}A sort direction.
PHP: Utopia\Query\OrderDirection.
Display.use utopia_query::QueryOrJson;pub enum QueryOrJson<'a> {
Query(&'a Query),
Json(&'a str),
}What Query::fingerprint accepts: a query, or its JSON.
use utopia_query::StringLiteral;pub enum StringLiteral {
Backslash,
BackslashUtf8,
Extended,
Standard,
}The rules a dialect's string literals follow.
PHP: Utopia\Query\StringLiteral.
use utopia_query::Type;pub enum Type {
Read,
Write,
TransactionBegin,
TransactionEnd,
Transaction,
Unknown,
}What kind of statement a classifier found.
PHP: Utopia\Query\Type.
Display.use utopia_query::Compiler;pub trait CompilerSomething that compiles queries: a builder.
PHP: Utopia\Query\Compiler.
use utopia_query::IntoValue;pub trait IntoValueSomething usable as one PHP value: integers, floats, booleans, strings,
arrays, queries, None for null.
use utopia_query::IntoValues;pub trait IntoValuesuse utopia_query::list;pub fn list<V: Into<Value>>(items: impl IntoIterator<Item = V>) -> ArrayA list of values.
use utopia_query::quote;pub fn quote(identifier: &str, wrap: char) -> Result<String>Quotes a possibly qualified identifier with wrap: each dot-separated
segment is wrapped (the wrap character doubled inside), a final *
stays bare, and * alone is returned as is. Control characters are
refused.
PHP: QuotesIdentifiers::quote() (with $wrapChar).
use utopia_query::quote;
assert_eq!(quote("schema.users", '`')?, "`schema`.`users`");
assert_eq!(quote("users.*", '"')?, "\"users\".*");use Utopia\Query\Builder\MySQL;
echo (new MySQL())->from('schema.users')->build()->query, "\n"; // SELECT * FROM `schema`.`users`use utopia_query::quote_literal;pub fn quote_literal(identifier: &str, wrap: char) -> Result<String>Quotes one identifier without treating dots as qualifiers (a column named
meta.key, as ClickHouse nested columns are).
PHP: QuotesIdentifiers::quoteLiteral().
use utopia_query::quote_literal;
assert_eq!(quote_literal("meta.key", '`')?, "`meta.key`");use Utopia\Query\Schema\ClickHouse;
echo (new ClickHouse())->table('t')->string('meta.key')->create()->query, "\n";use utopia_query::string;pub fn string(s: impl AsRef<[u8]>) -> ValueA string value.
pub type Array = Array<Object>;A PHP array of Values.
pub type Result<T, E = Error> = Result<T, E>;The result of the library's fallible operations.
pub type Value = Value<Object>;A value a query or a statement carries: a PHP value (bytes, integers
distinct from floats, ordered arrays with integer and string keys,
stdClass), where objects are Objects.
pub const DEFAULT_ALIAS: &str = "main";The alias a builder gives its main table when none is set.
PHP: Query::DEFAULT_ALIAS.
pub const GROUP_BY_TIME_BUCKET_INTERVALS: [&str; 7] = _;The bucket sizes groupByTimeBucket accepts.
PHP: Query::GROUP_BY_TIME_BUCKET_INTERVALS.