DammitMoonMoon
DammitMoonMoon
DTDrizzle Team
Created by DammitMoonMoon on 11/23/2023 in #help
"Prepared statement already exists" error
I'm experiencing a problem with Drizzle ORM and Vercel’s Postgres (which I believe is Neon Postgres under the hood) in my SvelteKit application deployed on Vercel. Everything functioned perfectly until I tried to transition my request handling to edge functions using prepared statements. Here’s what I've implemented: 1. Defined a prepared statement in a separate file:
export const getPublishedJokesPrep = db
.select()
.from(jokesTable)
.where(eq(jokesTable.isPublished, true))
.orderBy(desc(jokesTable.votes))
.prepare('getPublishedJokesPrep');
export const getPublishedJokesPrep = db
.select()
.from(jokesTable)
.where(eq(jokesTable.isPublished, true))
.orderBy(desc(jokesTable.votes))
.prepare('getPublishedJokesPrep');
2. Executed the prepared statement in the request handler: getPublishedJokesPrep.execute(); The first execution works fine, but subsequent ones trigger a “prepared statement already exists” error. It seems each request to the handler tries to recreate the prepared statement. This issue seems similar to what others have encountered (https://discord.com/channels/1043890932593987624/1150720833199808584, https://discord.com/channels/1043890932593987624/1124136214086299690), but there are no solutions in these threads. Has anyone faced and resolved this? Any insights into the root cause or potential solutions would be greatly appreciated.
9 replies