#Seeders not working with Prisma using Bun

1 messages · Page 1 of 1 (latest)

tropic shell
#

Hey guys ! I would love to get help with this : https://stackoverflow.com/q/77223291/16508587

In case Here is what on the stackoverflow :

So basically I'm trying for the first time bun with the Elysia framework and prisma for the ORM.

Here is my 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?
}

and here is my seed.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)
    })

And here is my 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"
  }
}

So, the issue is that the command "bunx prisma db push" works perfectly, it reads my schema.prisma , create the associated collections and "generate" my prisma client.

But the issue is that the "bun seed" command who basically do "bunx prisma db seed" who basically also do "bun utils/seed.ts" (that I also tried to do by hand) show this :

$ bunx prisma db seed
Environment variables loaded from .env
Running seed command `bun utils/seed.ts` ...

:seedling:  The seed command has been executed.

but in my database nothing was seeded, and strangely the console.log in the .then of the main seems to not being applied.

(ping me so I can easily see reply)

tropic shell
#

Hey, upping the thread, I really need help lmao i'm stuck since 3 days now ><

tropic shell
#

pretty please i'm out of solution to make it works 😢

gentle thorn
tropic shell
#

ce qui me pose problème c'est que j'ai aucune érreur de prompt c'est comme si dès que je faisais appel au prismaClient avec par exemple le "create" bah le script se coupe (je dis ça vu que les console.log dans le .then et .catch se font jamais)

boreal peak
#

Car .then/.catch c'est pour ce cas de figure normalement

#
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient()

async function main()
{
  return new Promise((resolve,reject) => {
try{
    await prisma.user.create({
        data:
        {
            name: "John Dough",
            email: `john-${Math.random()}@example.com`
        },
    })

    const count = await prisma.user.count()
    resolve(count);
    console.log(`There are ${count} users in the database.`)
}catch(e){
  reject(e)
}
})
}

main()
    .then(async (count) => {
        console.log("done ! GG !", count)
        await prisma.$disconnect()
    })
    .catch(async (error) => {
        console.error(error)
        await prisma.$disconnect()
        process.exit(1)
    })
#

Normalement avec ce code, ça fonctionnera

tropic shell
#

Je vais tester mais ... Si c'est le cas faut que la Doc de bun et la Doc de Prisma soit mise a jour ah ah

tropic shell
boreal peak
#

ah bah là je sais pas

tropic shell