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

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

Build the whole data layer from an emitted contract, in one call.

**Signature:**

```typescript
export declare function dataLayer(options: DataLayerOptions): DataLayer;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| options | [DataLayerOptions](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayeroptions/) | The contract, what cannot be derived, and the resolvers. |


**Returns:**

[DataLayer](https://imqueue.org/api/pg-prisma/latest/pg-prisma.datalayer/)

The middleware array and a teardown hook.

## Exceptions

When `scope` names a model the contract does not define.

## Remarks

The middlewares are returned already composed, which is the point: a caller never orders them and so cannot order them wrongly. Under Prisma 7 this was five `$extends` calls whose sequence every service repeated and any service could get wrong, with a soft delete losing its `deletedBy` and nothing reporting it. Here the two halves that were order-dependent are one middleware, and what remains genuinely commutes.

Reach for the individual factories only to compose something this does not cover; for the ordinary case this is the entry point.

## Example


```typescript
const layer = dataLayer({
    contract: contractJson,
    scope: { Portfolio: { portfolio: ['id'] } },
    resolvers: { portfolio: () => currentPortfolioIds() },
    getActorId: currentActorId,
});

export const db = postgres<Contract>({
    contractJson,
    url: config.db.url,
    middleware: layer.middleware,
});
```

