---
title: "Drizzle / Postgres"
description: "Use the current Drizzle ChatStore schema and shared Postgres client."
---

`createDrizzleChatStore()` returns the default self-hosted `ChatStoreFactory`.
It uses `DATABASE_URL` unless a connection string is passed explicitly.

```ts
import {
  createDrizzleChatStore,
  getDrizzleDb,
  schema,
} from '@mordn/chat-widget/server/drizzle';
```

```env
DATABASE_URL="postgres://user:password@host:5432/database"
```

## Current schema

The scaffolded `drizzle.config.ts` points directly to:

```ts
'./node_modules/@mordn/chat-widget/dist/server/drizzle/index.js'
```

Run:

```bash
npx drizzle-kit push
```

This creates `chat_conversations` and `chat_messages`. The `schema` exported from
`@mordn/chat-widget/server/drizzle` is the same current handler schema.

> **Warning**
>
> `@mordn/chat-widget/schema` is the legacy pre-handler schema entry and is not an
> alias for the current `server/drizzle` schema. Do not use it for a new handler
> installation.

## Handler wiring

```ts
export const { GET, POST, DELETE } = createChatHandler({
  getUserId: getChatUserId,
  model: anthropic('claude-sonnet-4-5'),
  store: createDrizzleChatStore(),
});
```


- **`connectionString`** · `string` · default `DATABASE_URL`

  Postgres connection string.

- **`max`** · `number` · default `5`

  Maximum pool connections.


The client disables prepared statements for transaction-mode poolers. Use
`getDrizzleDb()` for advanced queries against the shared pool.
