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

Source: https://imqueue.org/api/pg-prisma/latest/pg-prisma.toordering/
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 ordering into the callbacks `.orderBy()` takes.

**Signature:**

```typescript
export declare function toOrdering(orderBy: OrderBy | undefined): ((fields: Fields) => unknown)[];
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| orderBy | [OrderBy](https://imqueue.org/api/pg-prisma/latest/pg-prisma.orderby/) \| undefined | The ordering, or undefined for none. |


**Returns:**

((fields: [Fields](https://imqueue.org/api/pg-prisma/latest/pg-prisma.fields/)) => unknown)\[\]

One callback per key, in order; empty when nothing orders it.

## Remarks

One callback per sort key, because `.orderBy()` accepts a single item and additional keys are expressed by chaining it. Returning an array from the callback instead fails deep inside parameter collection with an unrecognisable error, so the shape is pinned here rather than left to a caller to rediscover.

## Example


```typescript
toOrdering({ createdAt: 'desc', id: 'asc' }).reduce(
    (query, by) => query.orderBy(by),
    db.orm.public.Session,
);
```

