---
title: TypeScript database access
description: Use server-only database helpers while preserving Relpin tenant isolation.
section: SDK
sidebarLabel: TypeScript / DB access
order: 100
updated: "2026-06-11"
status: beta
llms: true
keywords:
  - TypeScript
  - database
  - Drizzle
  - getWorkspaceDb
---

TypeScript apps use server-only database helpers for tenant data. The SDK can create a request-scoped Drizzle client or use the governed proxy path when the runtime requires it.

## Use request-scoped handles

```ts
import { withWorkspaceDb } from '@app-builder-platform/relpin-sdk/db'

export async function listOrders(env: Env) {
  return withWorkspaceDb({ env }, async (db) => {
    return db.execute('select id, status from orders limit 20')
  })
}
```

Close handles after each request. `withWorkspaceDb` does this automatically.

## Server-only boundary

The database helpers are server-only. If code runs in the browser, it should call a server route instead of importing the DB SDK.

## Container mode

In container preview, the SDK uses the proxy data path so the app does not receive the raw tenant connection string.
