Skip to main content

部署 Prisma ORM

使用 Prisma Client 的项目可以部署到许多不同的云平台。鉴于云平台的多样性和不同的名称,值得注意的是不同的部署范例,因为它们会影响你使用 Prisma Client 部署应用的方式。

¥Projects using Prisma Client can be deployed to many different cloud platforms. Given the variety of cloud platforms and different names, it's noteworthy to mention the different deployment paradigms, as they affect the way you deploy an application using Prisma Client.

不使用 Rust 二进制文件使用 Prisma ORM

如果 Prisma ORM 的 Rust 引擎二进制文件导致包体积过大、构建速度缓慢或部署问题(例如,在无服务器或边缘环境中),你可以使用 generator 块的以下配置来使用它,而无需使用它们:

¥If Prisma ORM's Rust engine binaries cause large bundle sizes, slow builds, or deployment issues (for example, in serverless or edge environments), you can use it without them using this configuration of your generator block:

generator client {
provider = "prisma-client-js" // or "prisma-client"
engineType = "client"
}

v6.16.0 以来,不带 Rust 二进制文件的 Prisma ORM 一直是 一般可用

¥Prisma ORM without Rust binaries has been Generally Available since v6.16.0.

请注意,在这种情况下,你需要使用 驱动适配器

¥Note that you need to use a driver adapter in this case.

使用此架构时:

¥When using this architecture:

  • 无需下载或安装 Rust 查询引擎二进制文件。

    ¥No Rust query engine binary is downloaded or shipped.

  • 数据库连接池由你安装的原生 JS 数据库驱动程序(例如,PostgreSQL 的 @prisma/adapter-pg)维护。

    ¥The database connection pool is maintained by the native JS database driver you install (e.g., @prisma/adapter-pg for PostgreSQL).

此设置可以简化无服务器或边缘运行时中的部署。在 文档在这里 中了解更多信息。

¥This setup can simplify deployments in serverless or edge runtimes. Learn more in the docs here.

好奇我们为什么放弃 Rust 引擎?了解为什么我们在 博客文章 中从 Rust 二进制引擎过渡到全 TypeScript 方法,以实现更快、更轻量的 Prisma ORM。

¥Curious why we moved away from the Rust engine? Take a look at why we transitioned from Rust binary engines to an all-TypeScript approach for a faster, lighter Prisma ORM in this blog post.

部署范例

¥Deployment paradigms

每种范例都有不同的权衡,这些权衡会影响应用的性能、可扩展性和运营成本。

¥Each paradigm has different tradeoffs that affect the performance, scalability, and operational costs of your application.

此外,应用的用户流量模式也是需要考虑的重要因素。例如,任何具有一致用户流量的应用可能更适合 持续运行范式,而具有突然峰值的应用可能更适合 serverless

¥Moreover, the user traffic pattern of your application is also an important factor to consider. For example, any application with consistent user traffic may be better suited for a continuously running paradigm, whereas an application with sudden spikes may be better suited to serverless.

传统服务器

¥Traditional servers

如果 Node.js 进程持续运行并同时处理多个请求,则你的应用是 传统部署。你的应用可以部署到平台即服务 (PaaS),如 Heroku科耶布Render;作为 Docker 容器部署到 Kubernetes;或作为虚拟机或裸机服务器上的 Node.js 进程。

¥Your application is traditionally deployed if a Node.js process is continuously running and handles multiple requests at the same time. Your application could be deployed to a Platform-as-a-Service (PaaS) like Heroku, Koyeb, or Render; as a Docker container to Kubernetes; or as a Node.js process on a virtual machine or bare metal server.

也可以看看:长时间运行的进程中的连接管理

¥See also: Connection management in long-running processes

无服务器函数

¥Serverless Functions

如果你的应用的 Node.js 进程(或其分解为函数的子集)在请求传入时启动,并且每个函数一次仅处理一个请求,则你的应用是 serverless。你的应用很可能会部署到功能即服务 (FaaS) 产品,例如 AWS LambdaAzure 函数

¥Your application is serverless if the Node.js processes of your application (or subsets of it broken into functions) are started as requests come in, and each function only handles one request at a time. Your application would most likely be deployed to a Function-as-a-Service (FaaS) offering, such as AWS Lambda or Azure Functions

无服务器环境具有热启动的概念,这意味着对于同一函数的后续调用,它可能会使用已分配的进程、内存、文件系统(/tmp 在 AWS Lambda 上可写)甚至数据库连接仍然可用的现有容器。

¥Serverless environments have the concept of warm starts, which means that for subsequent invocations of the same function, it may use an already existing container that has the allocated processes, memory, file system (/tmp is writable on AWS Lambda), and even DB connection still available.

通常,任何一段代码 在处理程序之外 都保持初始化状态。

¥Typically, any piece of code outside the handler remains initialized.

也可以看看:无服务器环境中的连接管理

¥See also: Connection management in serverless environments

边缘函数

¥Edge Functions

如果你的应用是 serverless 并且功能分布在靠近用户的一个或多个区域,那么你的应用就是 边缘部署

¥Your application is edge deployed if your application is serverless and the functions are distributed across one or more regions close to the user.

通常,边缘环境还具有与传统或无服务器环境不同的运行时,导致通用 API 不可用。

¥Typically, edge environments also have a different runtime than a traditional or serverless environment, leading to common APIs being unavailable.