Expand description
The queryweave runtime for the persistence layer: the traits and SQL the
code generated for entities and wrappers (Columns, AppendToQuery,
AppendConditions) names, on top of the core runtime
(queryweave), which it re-exports so that code names only this crate.
This is where the domain’s database-agnostic filters, sorting and writes
(queryweave::FilterCondition, queryweave::SortKey,
queryweave::FieldValue) become SQL. They name domain fields; the
Columns of the entity storing them say which column each lives in, and
write the SQL against them, into the query being built: any type
implementing the target traits (ConditionsTarget, OrderByTarget,
PageTarget, and AssignmentsTarget with merge patches).
§Features
sqlx(default): sqlx’sQueryBuilderis a target, for any database whose driver binds the domain’s raw values (BindValues).sea-query: sea-query’sSelectStatement(conditions,ORDER BY, page),UpdateStatement(conditions, assignments) andDeleteStatement(conditions) are targets. Withsea-orm, write into a query’s statement throughQueryTrait::query:Order::push_conditions(select.query(), …).diesel: thedieselmodule, the typed conditions, orderings, page and assignments of an entity’s Diesel columns, for the SQL types every backend has;diesel-postgres,diesel-mysqlanddiesel-sqliteadd each backend’s own date-time types.merge-patch(default): merge-patch writes (push_assignments).
The SQL is portable across Postgres, MySQL/MariaDB and SQLite. What stays
database-specific is semantics, not syntax: LIKE is case-sensitive on
Postgres but case-insensitive on SQLite (for ASCII) and under MySQL’s
default collations, and column names are written unquoted, so they must not
be reserved words of the database.
Modules§
- diesel
- Diesel’s typed query DSL as the target of a model’s data.
- sea_
query - sea-query’s statements as queries the SQL is written into.
Macros§
- assert_
columns - Assert at compile time that every one of
fieldshas a column onentity.
Structs§
- Change
Set - The names of the fields that changed, e.g. between a model and its merge-patched version.
- Field
Value - A domain field to write and the value to write to it, e.g. one changed field of a merge patch.
- Filter
Condition - One set filter of a generated filter-options model:
field operator value. - Message
- A message built at compile time (see
missing_column_message). - Model
Data - Items (
T) naming fields of the modelM, e.g. the set filters of a generated filter-options model. - Query
Builder - The sqlx query builder the clauses are appended to, and the separated
builder
Columns::push_assignmentsreturns for it: re-exported so callers can name the same sqlx as this crate, whatever they call their own sqlx dependency. A builder type for constructing queries at runtime. - Separated
- The sqlx query builder the clauses are appended to, and the separated
builder
Columns::push_assignmentsreturns for it: re-exported so callers can name the same sqlx as this crate, whatever they call their own sqlx dependency. A wrapper aroundQueryBuilderfor creating comma(or other token)-separated lists. - SortKey
- One sort key of a generated query model: sort by
fieldindirection. - Value
Type - What a raw type is as a
Value, at compile time: its variant, and whether it may be absent (NULL, anOption).
Enums§
- Filter
Operator - The comparison a generated filter field performs against its column.
- Junction
- How conditions are joined: every one must hold (
AND), or any (OR). - Patch
- A field of a merge patch that may also be cleared: absent from the patch,
set to
null, or given a value. - Sort
Direction Model - How the sorting direction is evaluated. How it is expressed in a query is up to the persistence layer.
- Value
- A raw value to compare against or store, in a database-agnostic form.
- Value
Kind - A
Valuevariant without its value: what a raw type converts into, known at compile time (IntoValue::TYPE).
Constants§
- LIKE_
ESCAPE - The character escaping the
LIKEmetacharacters in a bound pattern (escape_like), to name in the clause:… LIKE ? ESCAPE '!'.
Traits§
- Append
Conditions - Append a filter-options model’s set filters to a query as conditions.
- Append
ToQuery - Append the filters query to the parent query.
- Assignments
Target - A query that merge-patch writes can be written into: the assignments of an
UPDATE … SET. - Bind
Values - A database the SQL helpers can write for.
- Boolean
- A raw value the
boolfilter applies to. - Changed
Fields - Detect changes in field values.
- Columns
- A table (usually a
sqlxentity) whose columns store a domain model’s fields, and the SQL written for that model’s data against those columns. - Conditions
Target - A query that filter conditions can be written into: a
WHEREclause. - Filter
Options Of - A type converting into model
M’s filter options model. - Filterable
- The types
#[derive(Filters)]generates for a root model or a mirror, so code mirroring it names them through it instead of by name. - Into
Root Query - The query of
M(a root’s query model, or a mirror’s query parameters), converting along its chain of mirrored models into the root model’s query. - Into
Value - A raw value that can be handed to the persistence layer as a
Value. - Merge
Patch Nullable Fields - A merge patch model: which of its fields a client may set to
null(itsPatchfields), as opposed to leaving them out. - Names
Field - An item naming a domain field.
- Nullable
Fields - Which fields of a merge patch struct may be set to
null, under its own names. - Order
ByTarget - A query that sort keys can be written into: an
ORDER BYclause. - Ordered
- A raw value the
lt/gtfilters can compare. - Page
Target - A query that a page can be written into:
LIMITandOFFSET. - Patch
Field - A field of a merge patch, applied to the model’s field of type
F. - Patch
Kind - What a merge patch field can say: whether its kind of field may be set to
nullat all, and whether this one is. - Persisted
Fields - A type whose data names domain fields the persistence layer maps onto columns.
- QueryOf
- A type converting into model
M’s query model. - RawValue
- A domain field type with a raw value behind it: the value filters compare with and merge patches bind.
- Sort
Details Of - A type converting into model
M’s sort details. - Sort
Field Of - A sortable-fields enum mirroring model
M’s, variant for variant. - Text
- A raw value the
sw/c/ew(LIKE) filters can match.
Functions§
- column_
for - The column
fieldis stored in, per a(domain field, column)table. - escape_
like - Escape the
LIKEmetacharacters (%,_andLIKE_ESCAPEitself) so user input matches literally instead of acting as wildcards. - first_
field_ without_ column - The first of
fieldswithout a column in the(domain field, column)table, if any. Usable inconstcode, which is howassert_columns!checks coverage at compile time. - like_
pattern - The
LIKEpattern to bind for aLIKEoperator: the escaped text wrapped in%wildcards.Nonefor the comparison operators, which bind the value itself. - missing_
column_ message - The compile error
assert_columns!reports for a domain field without a column onentity. Built inconstcode, since aconstpanic cannot format its message. - page_
offset - The row offset of page
page(0 based) ofpage_sizerows, saturated ati64::MAX:u32 * u32always fits au64, and an offset past every database’s signed 64-bit row count just yields an empty page. - push_
page - Write a
LIMIT page_size OFFSET page * page_sizeclause, binding both, when both a page and a page size are requested; nothing otherwise. - sql_
direction - The SQL keyword for a sort direction.
- sql_
junction - The SQL keyword joining conditions.
- sql_
operator - The SQL comparison operator for a filter operator.
Type Aliases§
- Conditions
- The set filters of the model
M, as database-agnostic conditions. - Field
Values - Fields of the model
Mto write, with their values. - Sort
Keys - The requested sorting of the model
M, in order.