1.安装prisma
npm install @prisma/client
2.创建schema.prisma
npx prisma init
执行完命令后创建文件目录如下:
3.配置数据库连接
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite" //数据库类型 这里使用的是sqlite
url = "file:aigc.db" //数据库文件路径
}
4.逆向生成数据模型
npm run prisma:introspect
5.更新Prisma Client
npm run prisma:generate
6.简单代码里面尝试查询记录
import { NextResponse } from 'next/server'
import { PrismaClient } from '@prisma/client'
export async function GET(request: Request) {
const prisma = new PrismaClient()
const dataList = await prisma.thirdPartySdkAcountInfo.findMany()
return NextResponse.json({
dataList
})
}
正常输出 done