Skip to main content

将 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:

提示

从其他 ORM 迁移?查看我们针对 TypeORMSequelize 的专用指南。

¥Migrating from another ORM? Check out our dedicated guides for TypeORM and Sequelize.

先决条件

¥Prerequisites

开始之前,请确保你已具备以下条件:

¥Before you begin, ensure you have:

  • 包含 package.json 文件的现有 Node.js 项目

    ¥An existing Node.js project with a package.json file

  • Node.js 已安装(参见 系统要求

    ¥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

  1. 打开你的终端并导航到包含 package.json 的项目目录。

    ¥Open your terminal and navigate to the project directory containing your package.json.

  2. 安装 Prisma CLI 作为开发依赖:

    ¥Install Prisma CLI as a development dependency:

npm install prisma --save-dev