Skip to main content

数据源

数据源决定了 Prisma ORM 如何连接到你的数据库,并由 Prisma 模式中的 datasource 块表示。以下数据源使用 postgresql 提供程序并包含连接 URL:

¥A data source determines how Prisma ORM connects to your database, and is represented by the datasource block in the Prisma schema. The following data source uses the postgresql provider and includes a connection URL:

datasource db {
provider = "postgresql"
url = "postgresql://johndoe:mypassword@localhost:5432/mydb?schema=public"
}

一个 Prisma 架构只能有一个数据源。但是,你可以:

¥A Prisma schema can only have one data source. However, you can:

注意:2.22.0 中删除了多提供商支持。请参阅 弃用提供者数组表示法 了解更多信息。

¥Note: Multiple provider support was removed in 2.22.0. Please see Deprecation of provider array notation for more information.

保护数据库连接

¥Securing database connections

某些数据源 provider 允许你使用 SSL/TLS 配置连接,并为 url 提供参数以指定证书的位置。

¥Some data source providers allow you to configure your connection with SSL/TLS, and provide parameters for the url to specify the location of certificates.

Prisma ORM 解析相对于 ./prisma 目录的 SSL 证书。如果你的证书文件位于该目录之外,例如 你的项目根目录,使用证书的相对路径:

¥Prisma ORM resolves SSL certificates relative to the ./prisma directory. If your certificate files are located outside that directory, e.g. your project root directory, use relative paths for certificates:

注意

使用 多文件 Prisma Schema 时,Prisma ORM 会解析相对于 ./prisma/schema 目录的 SSL 证书。

¥When you're using a multi-file Prisma schema, Prisma ORM resolves SSL certificates relative to the ./prisma/schema directory.

datasource db {
provider = "postgresql"
url = "postgresql://johndoe:mypassword@localhost:5432/mydb?schema=public&sslmode=require&sslcert=../server-ca.pem&sslidentity=../client-identity.p12&sslpassword=<REDACTED>"
}