Ila*_*nil 2 mysql database orm node.js prisma
我正在尝试运行 Prisma 以使用 Node js 服务器与 MySQL 数据库集成。将 Prisma 架构迁移到 MySql 数据库后,我在 Mac Air m1 上收到以下错误,我已经验证数据库 URL 已正确配置。我尝试过强制清除缓存,重新安装npm,重新启动电脑,然后重新启动VsCode。
EPERM:不允许操作,utime '/Users/apple/.cache/prisma/master/bcc2ff906db47790ee902e7bbc76d7ffb1893009/darwin-arm64/prisma-fmt' apple@Apples-MacBook-Air 服务器%
当我尝试运行 server.js 文件时,出现以下错误
@prisma/client 尚未初始化。请运行“prismagenerate”并尝试再次导入。如果您意外出现此错误,请在https://github.com/prisma/prisma/issues 的新 PrismaClient (/Users/apple/Desktop/react-i/servers/node_modules/.prisma/client/ index.js:3:11) 在对象。(/Users/apple/Desktop/react-i/servers/authenticate.js:7:16) 在 Module._compile (node:internal/modules/cjs/loader:1101:14) 在 Object.Module._extensions..js (节点:内部/模块/cjs/loader:1153:10)在Module.load(节点:内部/模块/cjs/loader:981:32)在Function.Module._load(节点:内部/模块/cjs/loader :822:12) 在 Module.require (node:internal/modules/cjs/loader:1005:19) 在 require (node:internal/modules/cjs/helpers:102:18) 在 Object. (/Users/apple/Desktop/react-i/servers/server.js:7:18) 在 Module._compile (节点:internal/modules/cjs/loader:1101:14)
运行 npx prismagenerate再次出现第一个错误
任何帮助表示赞赏
这是相关服务器代码片段
const { PrismaClient } = require("@prisma/client");
const crypto = require('crypto');
const express = require('express');
const route = express.Router();
const jwt = require('jsonwebtoken');
const prisma = new PrismaClient();
const addUserToDb = async user => {
try {
const newUser = await prisma.users.create({
data: {
email: user.email,
username: user.username,
password: hashPassword(user.password),
isAdmin: true,
},
});
console.log(JSON.stringify(newUser));
} catch (e) {
console.error(e);
return 'problem adding user to db';
}
return 'user added to db';
};
const hashPassword = password => {
let salt = crypto.randomBytes(16).toString('hex');
hashedpwd = crypto.pbkdf2Sync(password, salt, 1000, 64, 'sha512');
console.log(hashedpwd);
return hashedpwd;
};
const generateToken = (user, time = '300s') =>
jwt.sign(user, process.env.ACCESS_TOKEN_SECRET, { expiresIn: time });
route.post('/register', (req, res) => {
let newUser = req.body.userRegister;
const accessToken = jwt.sign(newUser, process.env.ACCESS_TOKEN_SECRET);
res.json({ user: addUserToDb(newUser), token: accessToken });
});
module.exports = route;
//prisma.schema code
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Users {
id String @id @default(uuid())
username String @unique @db.VarChar(255)
email String? @unique @db.VarChar(255)
password String @db.VarChar(255)
refreshToken String?
passwordResetToken String?
profileImgUrl String?
customers Customers?
role String @default("user")
@@map(name: "users")
}
model Services {
id Int @id @default(autoincrement())
orders Orders[]
title String
description String
SAC String? @unique @db.VarChar(255)
@@map(name: "services")
}
model Customers {
customers Users @relation(fields: [customerId], references: [id])
customerId String @unique
firstName String
lastName String
phoneNumber Int
address String
State String
Pincode Int
City String?
orders Orders[]
@@map(name: "customers")
}
model Orders {
id Int @id @default(autoincrement())
value Float
createdAt DateTime @default(now())
service Services @relation(fields: [serviceId], references: [id])
serviceId Int
customer Customers @relation(fields: [customerId], references: [customerId])
customerId String
@@map(name: "orders")
}
model Reviews {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
starRating Int
content String?
@@map(name: "reviews")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3099 次 |
| 最近记录: |