# query namespace · @imqueue/pg-sequelize

Source: https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-sequelize 4.2.0 — generated reference, not hand-written

Turns a caller's serialized query into Sequelize options, and back out as SQL.

**Signature:**

```typescript
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 |
| --- | --- |
| [autoCountQuery(model, fields, merge)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.autocountquery/) | The counting counterpart of [query.autoQuery()](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.autoquery/), for the same fields and filter. |
| [autoQuery(model, fields, merge)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.autoquery/) | Builds Sequelize find options from a requested fields map, joins included. |
| [buildWhereFromArray(data)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.buildwherefromarray/) | ORs an array of filter values into one condition. |
| [createEntity(model, input, fields, transaction)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.createentity/) | Recursively creates entity and all it's relations from a given input using a given model. |
| [E(input)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.e/) | Renders a value as a SQL constant: a number as itself, a string quoted and escaped, anything else as `NULL`. |
| [filtered(attributes, fields, model)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.filtered/) | Intersects a set of attributes with the names a caller asked for. |
| [foreignKeys(model, relations)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.foreignkeys/) | Foreign-key column names on a model for the given relations. |
| [foreignKeysMap(parent, model)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.foreignkeysmap/) | Returns foreign key map for a given pair of parent model and related model. |
| [getInclude(queryOptions, path)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.getinclude/) | Finds the include options for a model reached through a chain of includes. |
| [L(str, values)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.l/) | Builds a Sequelize literal from a string or a template — the escape hatch for SQL that no query option can express. |
| [mergeQuery(queryOptions, merge)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.mergequery/) | Merges query-option fragments into one options object. |
| [needNesting(model, fields)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.neednesting/) | Whether a fields map asks for any of the model's relations. |
| [orNull(value)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.ornull/) | Matches a value, or no value at all. |
| [overrideJoin(queryOptions, options)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.overridejoin/) | 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. |
| [primaryKeys(model)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.primarykeys/) | Return names of primary key fields for a given model. |
| [pureFields(model, fields)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.purefields/) | Narrows a requested fields map to the model's own columns. |
| [safeSqlSpaceCleanup(input)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.safesqlspacecleanup/) | Collapses whitespace outside quoted literals, so a statement fits on one line. |
| [skip(obj, props)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.skip/) | Deletes properties from an object. |
| [sql(sqlQuery, values)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.sql/) | Normalises a SQL string: one-lined, whitespace collapsed, ending in a single semicolon. |
| [toLimitOptions(pageOptions)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.tolimitoptions/) | Builds proper paging options query part |
| [toOrderOptions(orderBy)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.toorderoptions/) | Turns a serialized order into Sequelize's `order` option. |
| [toWhereOptions(filter, inputType)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.towhereoptions/) | Turns a serializable filter into Sequelize `where` options. |
| [withRangeFilters(filter)](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.withrangefilters/) | Rewrites `<column>Range` filter properties onto the columns they belong to. |


## Interfaces


| Interface | Description |
| --- | --- |
| [ForeignKeyMap](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.foreignkeymap/) | Foreign key map representation, where related property name references parent property name. |
| [PureDataFunction](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.puredatafunction/) | The two shapes [query.pureData](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.puredata/) accepts: one record, or many. |


## Variables


| Variable | Description |
| --- | --- |
| [pureData](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.puredata/) | Keeps only the properties a model actually declares. |

