query namespace
Turns a caller's serialized query into Sequelize options, and back out as SQL.
Signature:
export declare namespace query
Remarks
The reason this package exists. A GraphQL API receives a filter, a page, an order and the set of fields the query selected — all of it plain JSON, none of it in a shape Sequelize accepts. These helpers translate: autoQuery is the one that composes the others, toWhereOptions turns a serialized filter into a where with the joins its nested parts imply, and toLimitOptions and toOrderOptions cover paging and ordering.
The efficiency comes from the fields map. A column nobody asked for is not selected and a relation nobody reached into is not joined, so the statement narrows as the caller's selection narrows rather than being fixed by the resolver.
Below that sit the escape hatches — sql, L and E — for the cases no option object can express.
Functions
|
Function |
Description |
|---|---|
|
The counting counterpart of query.autoQuery(), for the same fields and filter. | |
|
Builds Sequelize find options from a requested fields map, joins included. | |
|
ORs an array of filter values into one condition. | |
|
Recursively creates entity and all it's relations from a given input using a given model. | |
|
Renders a value as a SQL constant: a number as itself, a string quoted and escaped, anything else as | |
|
Intersects a set of attributes with the names a caller asked for. | |
|
Foreign-key column names on a model for the given relations. | |
|
Returns foreign key map for a given pair of parent model and related model. | |
|
Finds the include options for a model reached through a chain of includes. | |
|
Builds a Sequelize literal from a string or a template — the escape hatch for SQL that no query option can express. | |
|
Merges query-option fragments into one options object. | |
|
Whether a fields map asks for any of the model's relations. | |
|
Matches a value, or no value at all. | |
|
Traverses given query object, lookups for includes matching the given arguments of include options and overrides those are matching by model and alias with the provided option. | |
|
Return names of primary key fields for a given model. | |
|
Narrows a requested fields map to the model's own columns. | |
|
Collapses whitespace outside quoted literals, so a statement fits on one line. | |
|
Deletes properties from an object. | |
|
Normalises a SQL string: one-lined, whitespace collapsed, ending in a single semicolon. | |
|
Builds proper paging options query part | |
|
Turns a serialized order into Sequelize's | |
|
Turns a serializable filter into Sequelize | |
|
Rewrites |
Interfaces
|
Interface |
Description |
|---|---|
|
Foreign key map representation, where related property name references parent property name. | |
|
The two shapes query.pureData accepts: one record, or many. |
Variables
|
Variable |
Description |
|---|---|
|
Keeps only the properties a model actually declares. |