Vercel
Vercel Marketplace 与 Prisma Postgres 的集成 将你的 Vercel 项目与 Prisma Postgres 实例连接起来。连接后,集成将自动在你部署的 Vercel 应用上设置以下环境变量:
¥The Vercel Marketplace integration for Prisma Postgres connects your Vercel projects with Prisma Postgres instances. Once connected, the integration will automatically set the following environment variables on your deployed Vercel app:
POSTGRES_URL
:以 postgres://...
PRISMA_DATABASE_URL
开头的 直接 TCP 连接 URL:Prisma ORM 使用的连接 URL,以 prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
DATABASE_URL
开头:以 postgres://...
开头的 直接 TCP 连接 URL
¥POSTGRES_URL
: The direct TCP connection URL starting with postgres://...
PRISMA_DATABASE_URL
: The connection URL used by Prisma ORM starting with prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
DATABASE_URL
: The direct TCP connection URL starting with postgres://...
这些使你能够通过你想要使用的任何 ORM 或数据库库(Prisma ORM、Drizzle、Kysely 等)连接到 Prisma Postgres 实例。
¥These enable you to connect to the Prisma Postgres instances via any ORM or database library you want to use (Prisma ORM, Drizzle, Kysely, ...).
特性
¥Features
-
无需离开 Vercel 仪表板即可创建并使用 Prisma Postgres 实例。
¥Create and use Prisma Postgres instances without leaving the Vercel dashboard.
-
自动生成用于生产环境和预览环境的 Prisma Postgres URL。
¥Automatic generation of Prisma Postgres URLs for production and preview environments.
-
简化 Vercel 项目的环境配置。
¥Simplified environment configuration for your Vercel project.
-
用于升级/降级 Prisma Postgres 定价方案的计费工作流程。
¥Billing workflows to up-/ and downgrade your Prisma Postgres pricing plan.
-
适用于 Next.js、Nuxt、SvelteKit 以及各种 ORM 和 DB 库的可立即部署的全栈模板。
¥Ready-to-deploy fullstack templates for Next.js, Nuxt, SvelteKit and with various ORMs and DB libraries.
模板
¥Templates
在 Vercel Marketplace 上使用 Prisma Postgres 的最简单方法是通过以下模板之一:
¥The easiest way to use Prisma Postgres on the Vercel Marketplace is via one of the templates:
用法
¥Usage
安装扩展
¥Install the extension
要安装扩展程序,请点击 Prisma Postgres 集成页面 顶部的“安装”。
¥To install the extension, click Install at the top of the Prisma Postgres integration page.
集成现在将显示在你的集成列表中,例如 https://vercel.com/<VERCEL-TEAM>/~/integrations
。
¥The integration will now show up on your list of integrations, e.g. https://vercel.com/<VERCEL-TEAM>/~/integrations
.
创建一个新数据库
¥Create a new database
安装完成后,你可以导航到“存储”选项卡并点击“创建数据库”。
¥Once installed, you can navigate to the Storage tab and click Create Database.
选择 Prisma Postgres 并点击“继续”。然后选择数据库的区域和定价方案,并再次点击“继续”。
¥Select Prisma Postgres and click Continue. Then select the Region for the database and a Pricing Plan, and click Continue again.
最后,为数据库命名并点击“创建”。
¥Finally, give the database a Name and click Create.
数据库现已准备就绪,可以连接到你的 Vercel 项目。
¥The database is now ready and can be connected to your Vercel projects.
将数据库连接到 Vercel 项目
¥Connect database to Vercel project
在你的 Vercel 项目中,你现在可以点击“存储”选项卡,选择刚刚创建的数据库,然后点击“连接”。这将自动在该项目中设置 DATABASE_URL
环境变量,并使你的应用能够访问新创建的 Prisma Postgres 实例。
¥In your Vercel project, you can now click the Storage tab, select the database you just created and then click Connect. This will automatically set the DATABASE_URL
environment variable in that project and enable your application to access your newly created Prisma Postgres instance.
在 Prisma Studio 中查看和编辑数据
¥Viewing and editing data in Prisma Studio
要查看和编辑 Prisma Postgres 实例中的数据,你可以使用 Prisma 工作室 的本地版本。
¥To view and edit the data in your Prisma Postgres instance, you can use the local version of Prisma Studio.
在你设置了 DATABASE_URL
的本地项目版本中,运行以下命令打开 Prisma Studio:
¥In the local version of your project where you have your DATABASE_URL
set, run the following command to open Prisma Studio:
npx prisma studio
与 Prisma ORM 一起使用时的其他注意事项
¥Additional considerations when using with Prisma ORM
确保你的项目使用正确的环境变量
¥Ensure your project uses the correct environment variable
确保 schema.prisma
文件中的数据源已配置为使用 DATABASE_URL
或 PRISMA_DATABASE_URL
环境变量(具体取决于你在 Vercel 项目的“设置”中导出的是哪一个):
¥Ensure that the data source in your schema.prisma
file is configured to use the DATABASE_URL
or PRISMA_DATABASE_URL
environment variable (depending on which one is being exported in the Settings of your Vercel project):
// schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
在 package.json
中使用 postinstall
脚本生成 Prisma 客户端
¥Generate Prisma Client in a postinstall
script in package.json
为确保生成的 Prisma 客户端库在已部署的 Vercel 项目中可用,你应该将 postinstall
脚本添加到 package.json
文件的 scripts
部分:
¥To ensure the generated Prisma Client library is available on your deployed Vercel project, you should add a postinstall
script to the scripts
section of your package.json
file:
{
// ...
"scripts": {
// ...
"postinstall": "prisma generate --no-engine"
}
//
}
--no-engine
标志确保查询引擎二进制文件不包含在生成的 Prisma 客户端库中。使用 Prisma Postgres 时不需要它。
¥The --no-engine
flag ensures that the query engine binary is kept out of the generated Prisma Client library. It's not needed when using Prisma Postgres.