outerhell
outerhell
DTDrizzle Team
Created by DiamondDragon on 9/7/2023 in #help
No transactions support in neon-http driver even though neon provides a transaction function
Hello, I'm using drizzle neon-http driver and I was trying to create a transaction to do a many2many insert but it's not permitted. If I do the following it works
import { neon } from "@neondatabase/serverless";
const sql = neon(connectionStrPool.href);
await sql.transaction((tx) => [
tx`
INSERT INTO video (id, author_name, author_url, thumbnail_height, thumbnail_url, thumbnail_width, title, url)
VALUES (${videoId}, ${videoData.author_name}, ${videoData.author_url}, ${videoData.thumbnail_height}, ${videoData.thumbnail_url}, ${videoData.thumbnail_width}, ${videoData.title}, ${videoUrl})
ON CONFLICT DO NOTHING
`,
tx`
INSERT INTO user_video ("userId", "videoId")
VALUES (${userId}, ${videoId})
ON CONFLICT DO NOTHING
RETURNING "videoId"
`,
]);
import { neon } from "@neondatabase/serverless";
const sql = neon(connectionStrPool.href);
await sql.transaction((tx) => [
tx`
INSERT INTO video (id, author_name, author_url, thumbnail_height, thumbnail_url, thumbnail_width, title, url)
VALUES (${videoId}, ${videoData.author_name}, ${videoData.author_url}, ${videoData.thumbnail_height}, ${videoData.thumbnail_url}, ${videoData.thumbnail_width}, ${videoData.title}, ${videoUrl})
ON CONFLICT DO NOTHING
`,
tx`
INSERT INTO user_video ("userId", "videoId")
VALUES (${userId}, ${videoId})
ON CONFLICT DO NOTHING
RETURNING "videoId"
`,
]);
non-interactive transactions do the job, if the second insert fails nothing is added in the first insert. Is it supported by drizzle?
20 replies
TTCTheo's Typesafe Cult
Created by outerhell on 9/19/2022 in #questions
Avoid overriding last api response
I haven't used react query, I will give it a try, thanks!
5 replies
TTCTheo's Typesafe Cult
Created by outerhell on 9/19/2022 in #questions
Avoid overriding last api response
i'm using fetch
5 replies