Objection.js: Raw with Transactions

Created on 8 Mar 2018  路  1Comment  路  Source: Vincit/objection.js

Is there a way to fire up a raw query/insert/update with a transaction?
I cant find something in the docs whether here nor at the knex docs.

Thanks in advance!

Most helpful comment

Depending on how you use transactions, any of these should work:

await transaction(Person, async (Person) => {
  await Person.raw('select * from foo');
});
await transaction(Person, async (Person, trx) => {
  await trx.raw('select * from foo');
});
await transaction(Person.knex(), async (trx) => {
  await trx.raw('select * from foo');
});

It's documented here that the transaction object can be used as a knex instance.

>All comments

Depending on how you use transactions, any of these should work:

await transaction(Person, async (Person) => {
  await Person.raw('select * from foo');
});
await transaction(Person, async (Person, trx) => {
  await trx.raw('select * from foo');
});
await transaction(Person.knex(), async (trx) => {
  await trx.raw('select * from foo');
});

It's documented here that the transaction object can be used as a knex instance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apronin83 picture apronin83  路  3Comments

zacharynevin picture zacharynevin  路  4Comments

rickmed picture rickmed  路  4Comments

louis-etne picture louis-etne  路  4Comments

purepear picture purepear  路  3Comments