#Prisma killing immediately when used

1 messages · Page 1 of 1 (latest)

grand siren
#

Hello. I'm attempting to use Prisma with Bun, however I notice that it immediately kills any script that it is run with. I've installed Prisma correctly and have setup my .env file with a local PostgreSQL database. Running bunx prisma generate, bunx prisma db push, and bunx prisma validate works fine. This is my code:

import dotenv from "dotenv";
dotenv.config();

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

const url = process.env.DATABASE_URL;
console.log(`Database URL: ${url}`); // Database URL: postgresql://postgres:password@localhost:5432/?connection_limit=100

const prisma = new PrismaClient();
prisma.$connect().then(async (_) => {
    console.log("Connected to database"); // Never logs
});

I know for a fact that everything works as I have uninstalled and reinstalled PostgreSQL, upgraded my Bun version to both the stable and canary version, etc. The problem is that "Connected to database" is never logged. I've used similar code on a larger scale and encounter the same issue:

// Other file
export const init = async() => {
  // Do things with prisma
};

// index.ts
init(); // Process is killed here
doSomethingElse(); // never runs
umbral sage
#

I don't think you need the $connect().then()?

grand siren
#

ye ive tried await prisma.anime.count(), await prisma.$executeRaw, etc. but the same issue occurs

#

tried with and without the $connect() in case its the function itself, but it isn't

umbral sage
#

export const db = new PrismaClient()```
#

This is my Prisma init file which I import and immediately make db calls with

grand siren
#

ill try just using that 👍 ty

#

interesting that works perfectly fine. seems to be a problem with my setup. tysm for the help!

grand siren
#

For some reason it seems to only occur when I run this outside of index.ts. That's very strange hm

muted hill
#

@grand siren I'm trying to get bun+prisma.io+cockroachdb to work, and cockroachdb uses a PostgreSQL transport internally, so they likely share a lot of code.

Basically, it's like you said but worse. Any database call kills the app completely. If I try $connect, that also kills the app. I printed my DATABASE_URL and it's being loaded from .env correctly. If I delete node_modules, run yarn, and then make a couple of changes in tsconfig so that Node can run the code, everything works fine.

I only have index.ts at the moment, so running it in index.ts doesn't make it work. 😐 Would love to hear you tracked down what was broken.

grand siren
#

I unfortunately decided not to use Prisma entirely and went with Postgres instead. Couldn't get Prisma working at all

muted hill
#

I've used Prisma before, and I find it awesome. So my choice will likely be not to use Bun. 😭

#

Postgres is too low level for my taste. Prisma handles migrations and the creation of tables and type safety, all in one package. I know how to do all of that, but I have better uses for my time than to do it all manually.

hushed echo
#

Prisma sucks

#

it's slow

#

and use "pg" instead of postgres if you care about pools and speed, it's faster, and I think the native works too, so it's even faster than faster

muted hill
#

Prisma does what I need, and I am reluctant to try too many new technologies in one project. Bun was already a stretch, and frankly appears to be a bust.

At least if Bun had worked, I wouldn't need to learn much to use it. Ideally it would be faster and that's it. Switching to an unfamiliar query builder? I don't even know what I don't know I'll need to learn about its quirks and limitations.

west palm
#

Like

await prisma.user.findFirst({
select: {
id: true,
name: true
friends: {
select: {
photo: true
}
}
}
})
// {id: number, name: string, friends: {photo: string}[]}
toxic oak
hushed echo
#

@west palm it has types yes

grand siren
#

I had issues with Drizzle and Bun early on, but it might’ve been fixed later

#

Using a low level package might be the best solution in this case until bun:sql comes out

hushed echo
#

0

#

Except drizzle-kit but that's not a big deal

grand siren
#

Oh sick okay glad to hear that

dense spear
#

the above issue seems to be that bun is exiting early during async work

if you add a top level await on the async actions, this will likely be fine