Skip to content

Transaction

Christoph Herrmann edited this page Jun 14, 2019 · 6 revisions

It's possible to wrap multiple queries into a transaction which will be started and at the end committed. If an error is thrown, the transaction will be rollbacked.

await sql.transaction(async () => {
  const id = await sql.insert(
    'users', 
    { name: 'Sharaal', email: '[email protected]' }
  )
  await sql.insert('audits', { action: 'USER_CREATED', id })
})
Clone this wiki locally