npx create-db
create-db
是一个开源 CLI 工具,只需一条命令即可配置临时 Prisma Postgres 数据库。
¥create-db
is an open-source CLI tool that provisions temporary Prisma Postgres databases with a single command.
-
快速设置:无需注册即可创建临时的可用于生产的 Prisma Postgres 数据库。
¥Fast setup: No sign-up required to create a temporary production-ready Prisma Postgres database.
-
有效期:每个数据库默认可用 24 小时。
¥Lifetime: Each database is available for 24 hours by default.
-
免费保留:你可以通过 CLI 输出中提供的 URL 声明一个数据库,使其成为永久数据库。
¥Keep for free: You can claim a database (via the URL provided in the CLI output) to make it permanent.
先决条件
¥Prerequisites
要使用 npx create-db
,你需要:
¥To use npx create-db
, you need:
-
Node.js 版本
16
或更高版本(我们推荐使用最新的 LTS 版本)。¥Node.js version
16
or higher (we recommend the latest LTS version). -
npm(Node.js 自带)用于运行
npx
命令。¥npm (comes with Node.js) to run
npx
commands.
创建临时数据库不需要 Prisma Data Platform 账户。但是,如果你想永久保留数据库,可以声明它(详情以下)。
¥A Prisma Data Platform account is not required to create a temporary database. However, if you want to keep a database permanently, you can claim it (details below).
入门
¥Getting started
你可以使用以下选项之一创建数据库:
¥You can create a database using one of the following options:
选项 1:使用默认设置快速启动
¥Option 1: Quick start with default settings
在你的终端中运行以下命令:
¥Run the following command in your terminal:
npx create-db@latest
-
@latest
标签会自动下载并运行该工具的最新版本,因此无需全局安装。¥The
@latest
tag automatically downloads and runs the latest version of the tool, hence, no global installation required. -
几秒钟后,你将收到 Prisma ORM 项目和标准 PostgreSQL 的连接字符串。
¥After a few seconds, you'll receive connection strings for both Prisma ORM projects and standard PostgreSQL.
-
默认区域为
us-east-1
。你可以使用--region
标志指定要在其中配置数据库的区域。请参阅 以下部分 以查看所有 CLI 选项。¥The default region is
us-east-1
. You can specify the region where you want to provision the database in using the--region
flag. See the section below to view all the CLI options.
选项 2:以交互方式选择区域
¥Option 2: Choose a region interactively
如果你想手动选择区域:
¥If you want to select a region manually:
npx create-db@latest --interactive
-
这将打开一个区域选择菜单(例如,
us-east-1
、eu-west-3
)。¥This opens a region selection menu (for example,
us-east-1
,eu-west-3
). -
或者,你可以使用简写
-i
:¥Alternatively, you can use the shorthand
-i
:
npx create-db@latest -i
要查看所有选项和区域:
¥To view all options and regions:
npx create-db@latest --help
CLI 输出演示
¥CLI output walkthrough
以下是示例输出:
¥Here is an example output:
┌ 🚀 Creating a Prisma Postgres database
│
│ Provisioning a temporary database in us-east-1...
│
│ It will be automatically deleted in 24 hours, but you can claim it.
│
◇ Database created successfully!
│
● Connect to your database →
│
│ Use this connection string optimized for Prisma ORM:
│ prisma+postgres://accelerate.prisma-data.net/?api_key=...
│
│ Use this connection string for everything else:
│ postgresql://<username>:<password>@db.prisma.io:5432/postgres
│
◆ Claim your database →
│
│ Want to keep your database? Claim for free:
│ https://create-db.prisma.io?projectID=proj_...
└
获得输出后,获取 Prisma ORM 优化的连接字符串 (prisma+postgres://...
),并将其作为 DATABASE_URL
添加到你的 .env
文件中:
¥Once you have the output, take the Prisma ORM-optimized connection string (prisma+postgres://...
) and add it to your .env
file as DATABASE_URL
:
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=..."
你现在可以按照 Prisma Postgres 快速入门指南 将你的 Prisma 项目连接到此数据库。
¥You can now follow the Prisma Postgres quickstart guide to connect your Prisma project to this database.
如果你正在使用其他工具或库,请将标准 PostgreSQL 连接字符串 (postgresql://...
) 与任何兼容 PostgreSQL 的客户端(例如 psql
、pgAdmin
、node-postgres
或你选择的 ORM)一起使用。详细说明请参阅 通过直接 PostgreSQL 连接字符串连接 指南。
¥If you're using other tools or libraries, use the standard PostgreSQL connection string (postgresql://...
) with any PostgreSQL-compatible client, such as psql
, pgAdmin
, node-postgres
, or an ORM of your choice. Detailed instructions are available in the guide for connecting via direct PostgreSQL connection string.
声明数据库
¥Claiming your database
默认情况下,使用 npx create-db
创建的数据库是临时的,将在 24 小时后自动删除。
¥By default, databases created with npx create-db
are temporary and will be automatically deleted after 24 hours.
你可以使用 CLI 输出中显示的声明 URL 声明数据库来防止这种情况:
¥You can prevent this by claiming the database using the claim URL shown in the CLI output:
◆ Claim your database →
│
│ Want to keep your database? Claim for free:
│
│ https://create-db.prisma.io?projectID=proj_...
│
│ Your database will be deleted on 7/24/2025, 2:25:41 AM if not claimed.
要声明你的数据库并使其永久生效:
¥To claim your database and make it permanent:
-
从 CLI 输出中复制声明 URL。
¥Copy the claim URL from the CLI output.
-
在浏览器中打开它,然后单击“声明数据库”。
¥Open it in your browser and click Claim database.
-
登录你的 (如果你还没有,请创建一个)。
¥Sign in to your (or create one if you don’t have it yet).
-
选择一个能够创建新项目的工作区。
¥Choose a Workspace that has capacity for creating new projects.
-
点击“授权 Prisma 创建数据库”进行确认。
¥Click Authorize Prisma Create DB to confirm.
-
你将被重定向到成功页面。然后,点击“开始”,使用你的数据库查看和管理工作区中已声明的数据库。
¥You’ll be redirected to a success page. Then, click Go use your database to view and manage the claimed database in your workspace.
声明数据库时:
¥When you claim a database:
-
它已移至你的 Prisma Data Platform 账户工作区。
¥It's moved into your Prisma Data Platform account workspace.
-
它不会再在 24 小时后自动删除。
¥It's no longer auto-deleted after 24 hours.
-
你可以继续将其用作永久数据库实例。
¥You can continue using it as a permanent database instance.
可用的 CLI 选项
¥Available CLI options
以下是 npx create-db
命令的 CLI 标志:
¥Here are the CLI flags for the npx create-db
command:
标记 | 简写 | 描述 |
---|---|---|
--region | -r | 指定区域。 可用区域:ap-southeast-1 、ap-northeast-1 、eu-central-1 、eu-west-3 、us-east-1 、us-west-1 |
--interactive | -i | 以交互模式运行(从列表中选择区域)。 |
--help | -h | 显示此帮助消息。 |
要查看所有 CLI 选项,请使用 --help
或 -h
标志:
¥To view all CLI options use the --help
or -h
flag:
npx create-db@latest --help