Drizzle 服务器无服务性能

无服务函数(如 AWS Lamba 或 Vercel 服务器函数,它们基于 AWS Lamba)上您可以获得巨大的好处,因为它们可以长达 15 分钟,并且可以重复使用数据库连接和预编译语句。

另一方面,边缘函数 tend 倾向于在被调用后立即清理,这导致几乎没有性能收益。

要重用您的数据库连接和预编译语句,您只需在处理程序范围之外声明它们:

const databaseConnection = ...;
const db = drizzle(databaseConnection);
const prepared = db.select().from(...).prepare();

// AWS handler
export const handler = async (event: APIGatewayProxyEvent) => {
  return prepared.execute();
}
Become a Gold Sponsor