# toPredicate() function · @imqueue/pg-prisma

Source: https://imqueue.org/api/pg-prisma/latest/pg-prisma.topredicate/
Published: 2026-08-28
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-prisma 2.0.0 — generated reference, not hand-written

Turn a wire filter into the predicate callback `.where()` takes.

**Signature:**

```typescript
export declare function toPredicate(relations: RelationMap, model: string, where: Where | undefined): ((fields: Fields) => AnyExpression) | undefined;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| relations | [RelationMap](https://imqueue.org/api/pg-prisma/latest/pg-prisma.relationmap/) | Relations per model, from `deriveDataLayer`. |
| model | string | The model the filter is written against. |
| where | [Where](https://imqueue.org/api/pg-prisma/latest/pg-prisma.where/) \| undefined | The filter, or undefined for none. |


**Returns:**

((fields: [Fields](https://imqueue.org/api/pg-prisma/latest/pg-prisma.fields/)) => AnyExpression) \| undefined

The callback, or undefined when nothing constrains the query.

## Remarks

A relation filters through `some`, matching the wire shape's meaning: a condition on a list relation asks whether \*\*any\*\* related row satisfies it.

`contains`, `startsWith` and `endsWith` become `LIKE`, with the operand escaped — a caller searching for a literal `%` or `_` would otherwise get a wildcard, and the surprise is silent because the query still succeeds.

## Example


```typescript
const predicate = toPredicate(relations, 'User', {
    email: { contains: '@example.com' },
    roles: { role: { name: { eq: 'admin' } } },
});
const rows = await db.orm.public.User.where(predicate!).all();
```

