toPredicate() function
Turn a wire filter into the predicate callback .where() takes.
Signature:
export declare function toPredicate(relations: RelationMap, model: string, where: Where | undefined): ((fields: Fields) => AnyExpression) | undefined;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
relations |
Relations per model, from | |
|
model |
string |
The model the filter is written against. |
|
where |
Where | undefined |
The filter, or undefined for none. |
Returns:
((fields: 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
const predicate = toPredicate(relations, 'User', {
email: { contains: '@example.com' },
roles: { role: { name: { eq: 'admin' } } },
});
const rows = await db.orm.public.User.where(predicate!).all();
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.