Become a Gold Sponsor

Drizzle <> AWS 数据 API Postgres

This guide assumes familiarity with:

第一步 - 安装包

npm
yarn
pnpm
bun
npm i drizzle-orm @aws-sdk/client-rds-data
npm i -D drizzle-kit

第二步 - 初始化驱动程序并进行查询

import { drizzle } from 'drizzle-orm/aws-data-api-pg';

// 这三个属性是必需的。您也可以在连接对象中指定
// RDSDataClient 类型的任何属性。
const db = drizzle({ connection: {
  database: process.env['DATABASE']!,
  secretArn: process.env['SECRET_ARN']!,
  resourceArn: process.env['RESOURCE_ARN']!,
}});

await db.select().from(...);

如果您需要提供您现有的驱动程序:

import { drizzle } from 'drizzle-orm/aws-data-api/pg';
import { RDSDataClient } from '@aws-sdk/client-rds-data';

const rdsClient = new RDSDataClient({ region: 'us-east-1' });

const db = drizzle(rdsClient, {
  database: process.env['DATABASE']!,
  secretArn: process.env['SECRET_ARN']!,
  resourceArn: process.env['RESOURCE_ARN']!,
});

await db.select().from(...);

接下来是什么?