Drizzle + Neon postgres + NestJS setup help

Hello I have this setup working locally, I found a video setting up NestJS with drizzle but there was no neon. Everything works, but when making a couple of same requests from the frontend I get a NeonDbError: Error connecting to database: fetch failed, could someone help me with the cause of this issue? I have a database provider -
export const DrizzleAsyncProvider = 'drizzleProvider'

export const drizzleProvider = [
{
provide: DrizzleAsyncProvider,
useFactory: () => {
const sql = neon(process.env.DB_URL)
const db = drizzle(sql, { schema: schemas })
return db
},
exports: [DrizzleAsyncProvider],
},
]
export const DrizzleAsyncProvider = 'drizzleProvider'

export const drizzleProvider = [
{
provide: DrizzleAsyncProvider,
useFactory: () => {
const sql = neon(process.env.DB_URL)
const db = drizzle(sql, { schema: schemas })
return db
},
exports: [DrizzleAsyncProvider],
},
]
Then I inject the provider in some service that I need the db for like this -
constructor(@Inject(DrizzleAsyncProvider) private db: NeonHttpDatabase) {}
constructor(@Inject(DrizzleAsyncProvider) private db: NeonHttpDatabase) {}
And a db query example just in case -
async findOne(id: number) {
const query = await this.db.select().from(product).where(eq(product.id, id))
console.log(query)

return query[0]
}
async findOne(id: number) {
const query = await this.db.select().from(product).where(eq(product.id, id))
console.log(query)

return query[0]
}
1 Reply
Drakon
DrakonOP11mo ago
It feels like instead of the server having a connection to the db it connects, executes queries then disconnects, and if to many requests go in it flips on itself, if so, is there any way to create a normal db connection with nestJS pattern like people do with prisma?
Want results from more Discord servers?
Add your server