Vercel Postgres, no transactions?
I had problems using Kysely on Vercel Postgres, with the @vercel/postgres
and @vercel/postgres-kysely
adapters.
Basically, transactions are not supported.
I had some code like this:
const data = await db.transaction().execute(async (trx) => {
const somedata = await trx
.selectFrom('table1')
.selectAll()
.where('id', '=', token)
.executeTakeFirst()
if (!somedata) throw new Error('Invalid data')
await trx
.deleteFrom('table2')
.where('id', '=', token)
.executeTakeFirst()
return somedata
})
console.log(data)
and I had to remove the transaction, I just used the queries without the transaction:
const data = await db.selectFrom('table1')
.selectAll()
.where('id', '=', token)
.executeTakeFirst()
if (!data) throw new Error('Invalid data')
await db.deleteFrom('table2')
.where('id', '=', token)
.executeTakeFirst()
console.log(data)
Hopefully transactions will be implemented.
If you absolutely need them you can still use a direct connection to the database using pg
→ Download my free SQL Handbook!
THE VALLEY OF CODE
THE WEB DEVELOPER's MANUAL
You might be interested in those things I do:
- Learn to code in THE VALLEY OF CODE, your your web development manual
- Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
- I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
- Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
- Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
- Find me on X