所以基本上我是第一次尝试使用 Elysia 框架和 ORM 的 prisma。
这是我的 schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String?
}
这是我的种子。ts
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
async function main()
{
await prisma.user.create({
data:
{
name: "John Dough",
email: `john-${Math.random()}@example.com`
},
})
const count = await prisma.user.count()
console.log(`There are ${count} users in the database.`)
}
main()
.then(async () => {
console.log("done ! GG !")
await prisma.$disconnect()
})
.catch(async (error) => {
console.error(error)
await prisma.$disconnect()
process.exit(1)
})
这是我的 package.json
{
"name": "elysia",
"version": "1.0.50",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "bun run --watch src/index.ts",
"seed": "bunx prisma db seed"
},
"dependencies": {
"@elysiajs/swagger": "^0.7.3",
"@prisma/client": "^5.3.1",
"bson": "^6.1.0",
"elysia": "latest",
"prisma": "^5.3.1"
},
"devDependencies": {
"bun-types": "latest"
},
"module": "src/index.ts",
"prisma": {
"seed": "bun utils/seed.ts"
}
}
所以,问题是命令“bunx prisma db Push”工作完美,它读取我的 schema.prisma ,创建关联的集合并“生成”我的 prisma 客户端。
但问题是,“bun seeds”命令基本上执行“bunx prisma db seeds”,基本上也执行“bun utils/seed.ts”(我也尝试手动执行)显示了这一点:
$ bunx prisma db seed
Environment variables loaded from .env
Running seed command `bun utils/seed.ts` ...
🌱 The seed command has been executed.
但在我的数据库中没有任何种子,奇怪的是,主文件中的 .then 中的 console.log 似乎没有被应用。
好吧,看来这是发髻一侧的错误!这是偷看者所做的解决方法声明:github comment
不是棱镜的尽头希望它能尽快解决!