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
I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter
- C Handbook
- Command Line Handbook
- CSS Handbook
- Express Handbook
- Git Cheat Sheet
- Go Handbook
- HTML Handbook
- JS Handbook
- Laravel Handbook
- Next.js Handbook
- Node.js Handbook
- PHP Handbook
- Python Handbook
- React Handbook
- SQL Handbook
- Svelte Handbook
- Swift Handbook
JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025