# query.toWhereOptions() function · @imqueue/pg-sequelize

Source: https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.query.towhereoptions/
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 serializable filter into Sequelize `where` options.

**Signature:**

```typescript
export function toWhereOptions<T>(filter?: T, inputType?: new () => T): any;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| filter | T | _(Optional)_ Filter from a caller. Modified in place as empties are cleared. |
| inputType | new () => T | _(Optional)_ Constructor describing which properties are relations. |


**Returns:**

any

Options carrying `where` and, where relations were filtered, `include`.

## Remarks

Each property is dispatched on its shape: a `$`-prefixed key becomes the matching Sequelize operator (see [FILTER\_OPS](https://imqueue.org/api/pg-sequelize/latest/pg-sequelize.filter_ops/)), an object with `start` and `end` becomes a `BETWEEN`, any other object is walked recursively as a nested filter, an array becomes an OR of its values, and a scalar is compared directly.

A STRING value is inspected before it is compared, which is convenient and occasionally surprising. A `%` anywhere in it makes the comparison a case-insensitive `ILIKE`, and a leading `<=`, `>=`, `<`, `>` or `=` becomes that operator with the rest as the value, coerced to a number or a `Date` when it parses as one. So `'>=10'` and `'%abc%'` work with no operator key — and a literal value that happens to contain `%`, such as `'50% off'`, becomes a pattern match rather than an equality test. Use an explicit `$eq` where that matters.

Empty is treated as absent, not as a contradiction: an empty array is skipped and a single-element array is unwrapped to the value. Given a falsy filter it returns `{}`, which means "no restriction" — so a caller cannot accidentally filter everything out by passing nothing.

With `inputType`, a property matching one of that type's own properties is turned into a required `include` on the related model rather than a column comparison, which is how a filter reaches across a relation.

