Skip to main content

Crate queryweave_sql

Crate queryweave_sql 

Source
Expand description

The queryweave runtime for the persistence layer: the traits and SQL the code generated for entities and wrappers (Columns, AppendToQuery, AppendToQueryWithSeparator) 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.

The SQL is portable across the databases sqlx supports: Postgres, MySQL/MariaDB and SQLite (any BindValues database). 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.

Macros§

assert_columns
Assert at compile time that every one of fields has a column on entity.

Structs§

ChangeSet
The names of the fields that changed, e.g. between a model and its merge-patched version.
FieldValue
A domain field to write and the value to write to it, e.g. one changed field of a merge patch.
FilterCondition
One set filter of a generated filter-options model: field operator value.
Message
A message built at compile time (see missing_column_message).
ModelData
Items (T) naming fields of the model M, e.g. the set filters of a generated filter-options model.
QueryBuilder
The sqlx query builder the clauses are appended to, and the separated builder Columns::push_assignments returns: re-exported so the generated code (and its callers) name the same sqlx as this crate, whatever the user calls 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_assignments returns: re-exported so the generated code (and its callers) name the same sqlx as this crate, whatever the user calls their own sqlx dependency. A wrapper around QueryBuilder for creating comma(or other token)-separated lists.
SortKey
One sort key of a generated query model: sort by field in direction.

Enums§

FilterOperator
The comparison a generated filter field performs against its column.
Patch
A field of a merge patch that may also be cleared: absent from the patch, set to null, or given a value.
SortDirectionModel
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.

Traits§

AppendToQuery
Append the filters query to the parent query.
AppendToQueryWithSeparator
Append to query individual filters.
BindValues
A database the SQL helpers can write for.
Boolean
A raw value the bool filter applies to.
ChangedFields
Detect changes in field values.
Columns
A table (usually a sqlx entity) whose columns store a domain model’s fields, and the SQL written for that model’s data against those columns.
FilterOptionsOf
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.
IntoRootQuery
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.
IntoValue
A raw value that can be handed to the persistence layer as a Value.
MergePatchNullableFields
A merge patch model: which of its fields a client may set to null (its Patch fields), as opposed to leaving them out.
NamesField
An item naming a domain field.
NullableFields
Which fields of a merge patch struct may be set to null, under its own names.
Ordered
A raw value the lt / gt filters can compare.
PatchField
A field of a merge patch, applied to the model’s field of type F.
PatchKind
What a merge patch field can say: whether its kind of field may be set to null at all, and whether this one is.
PersistedFields
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.
SortDetailsOf
A type converting into model M’s sort details.
SortFieldOf
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 field is stored in, per a (domain field, column) table.
first_field_without_column
The first of fields without a column in the (domain field, column) table, if any. Usable in const code, which is how assert_columns! checks coverage at compile time.
missing_column_message
The compile error assert_columns! reports for a domain field without a column on entity. Built in const code, since a const panic cannot format its message.
push_page
Push a LIMIT page_size OFFSET page * page_size clause, binding both, when both a page and a page size are requested; nothing otherwise.
sql_direction
The SQL keyword for a sort direction.
sql_operator
The SQL comparison operator for a filter operator.

Type Aliases§

Conditions
The set filters of the model M, as database-agnostic conditions.
FieldValues
Fields of the model M to write, with their values.
SortKeys
The requested sorting of the model M, in order.