将 Prisma ORM 添加到现有项目 (TypeScript 和 MySQL)
概述
¥Overview
本指南将指导你将 Prisma ORM 集成到现有的 Node.js 或 TypeScript 项目中。你将学习如何:
¥This guide walks you through integrating Prisma ORM into an existing Node.js or TypeScript project. You'll learn how to:
-
将 Prisma 连接到你的 MySQL 数据库
¥Connect Prisma to your MySQL database
-
使用 Prisma CLI
¥Use the Prisma CLI
-
生成用于数据库访问的 Prisma 客户端
¥Generate a Prisma Client for database access
-
使用 Prisma 内省 内省你现有的数据库模式
¥Introspect your existing database schema using Prisma Introspection
先决条件
¥Prerequisites
开始之前,请确保你已具备以下条件:
¥Before you begin, ensure you have:
-
包含
package.json
文件的现有 Node.js 项目¥An existing Node.js project with a
package.json
file -
¥Node.js installed (see system requirements)
-
一个正在运行的 MySQL 数据库,至少包含一个表
¥A running MySQL database with at least one table
📌 你需要你的 数据库连接 URL,包括凭据。
¥📌 You'll need your database connection URL, including credentials.
💡 还没有数据库?尝试使用 SQLite 的 快速入门指南 来探索 Prisma ORM。
¥💡 Don’t have a database yet? Try our Quickstart guide with SQLite to explore Prisma ORM.
步骤 1:设置 Prisma
¥Step 1: Set Up Prisma
-
打开你的终端并导航到包含
package.json
的项目目录。¥Open your terminal and navigate to the project directory containing your
package.json
. -
安装 Prisma CLI 作为开发依赖:
¥Install Prisma CLI as a development dependency:
npm install prisma --save-dev