next-era
Version:
Welcome to **Next Era**! A comprehensive library designed to supercharge your **Next.js** applications with powerful utilities and significant performance optimizations. Build faster, more efficient, and feature-rich Next.js projects with ease.
18 lines (17 loc) • 507 B
JavaScript
/**
* Around with a try catch block that is able to rollback the transaction. Adapted from vercel/postgres.
* @param query - The promise object to query DataBase.
* @returns A new promise object that is arounded with.
*/
export default async function withTransaction(sql, query) {
try {
await sql.query("BEGIN");
const result = await query;
await sql.query("COMMIT");
return result;
}
catch (e) {
await sql.query("ROLLBACK");
throw e;
}
}