> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stacknext.space/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> StackNext documentation is written for developers using StackNext in a Next.js App Router project. Use the getting-started and guides sections to install and operate the product, and the reference section for CLI, configuration, MCP and package surfaces. Version-matched package API reference ships inside each npm package under node_modules/@stacknext/<package>/docs/ and is preferred over this site for installed-version APIs. Diagnostic findings are evidence, not confirmed root causes; regression comparisons are deterministic and report-only. Contributor and repository-maintenance documentation is not part of this site.

# Database integrations

> Add Drizzle or Prisma query evidence without capturing SQL bind parameters.

StackNext accepts query events from optional adapter packages. Both adapters
send SQL text after redaction and never send bind parameters.

| ORM | Package | Duration | Registration |
| - | - | - | - |
| Drizzle | `@stacknext/drizzle` | `null` (unmeasured) | Pass the logger to `drizzle()` |
| Prisma | `@stacknext/prisma` | Measured when Prisma provides it | Call `instrumentPrismaClient(client)` |

Neither package is required for core telemetry, and neither is installed
transitively by `@stacknext/next`. Add only the adapter the app uses.

## Drizzle

Install the adapter:

```bash theme={null}
pnpm add @stacknext/drizzle
```

Add the logger when you create the client:

```ts theme={null}
import { drizzle } from 'drizzle-orm/better-sqlite3'
import { createStackNextDrizzleLogger } from '@stacknext/drizzle'

export const db = drizzle(client, {
  logger: createStackNextDrizzleLogger({ databaseSystem: 'sqlite' }),
})
```

> [!WARNING]
>
> Drizzle's logger does not expose duration. Queries appear with
> `durationMs: null`; never rank or average them as if they were fast. Bind
> parameters are counted but never read or sent.

Set `database.drizzle` to `true` in `stacknext.config.json` so `init`, `doctor`
and coverage can describe the intended setup. The flag does not register the
logger.

## Prisma

Install the adapter:

```bash theme={null}
pnpm add @stacknext/prisma
```

Prisma must be configured to emit query events. Then register the adapter:

```ts theme={null}
import { PrismaClient } from '@prisma/client'
import { instrumentPrismaClient } from '@stacknext/prisma'

const prisma = new PrismaClient({
  log: [{ emit: 'event', level: 'query' }],
})

const stop = instrumentPrismaClient(prisma, {
  databaseSystem: 'postgresql',
})
// Optional: call stop() during shutdown.
```

The event-based `query` log level is required. `instrumentPrismaClient` is
idempotent for the same client and returns a stop function. Prisma query events
include a duration; SQL text is redacted and `params` are never read.

Set `database.prisma` to `true` in `stacknext.config.json` for the same setup
hints. The flag does not attach the event handler.

## Verify

Make a request that queries the database, then check the **Database** page or:

```bash theme={null}
pnpm exec stacknext coverage
```

`not-observed` means the current sample has no query evidence, not necessarily
that the adapter is broken. A working app with no database traffic in the
retention window also reports no queries.

![Database view listing redacted SQL shapes with ORM, operation, duration and trace correlation](https://mintcdn.com/stack-next/wvbZ0Zo0GO0UM1X7/screenshots/database.png?fit=max\&auto=format\&n=wvbZ0Zo0GO0UM1X7\&q=85\&s=5d48cc5269978bc16e6a716cb70ddbd4)

![Database view listing redacted SQL shapes with ORM, operation, duration and trace correlation](https://mintcdn.com/stack-next/wvbZ0Zo0GO0UM1X7/screenshots/database-dark.png?fit=max\&auto=format\&n=wvbZ0Zo0GO0UM1X7\&q=85\&s=4d8ec3ed5e19821c5235ebbc217e0a01)

## Limits

* Query text uses pattern-based redaction and may retain placeholders such as
  `$1` and `?`, as well as inline literals. Bind values are never captured.
* Drizzle durations are `null`. Never compare them with Prisma durations as if
  both were measured.
* StackNext does not run SQL, `EXPLAIN` or index analysis.
* Database coverage is per adapter registration. StackNext does not infer which
  ORM you use at runtime.

## Related

* [Configuration](https://docs.stacknext.space/reference/configuration.md)
* [Runtime evidence](https://docs.stacknext.space/guides/runtime-evidence.md)
* [Instrumentation coverage](https://docs.stacknext.space/instrumentation-coverage.md)
* [Privacy](https://docs.stacknext.space/privacy.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.