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

vladshcherbin picture vladshcherbin  路  74Comments

amiuhle picture amiuhle  路  40Comments

janl picture janl  路  31Comments

koskimas picture koskimas  路  26Comments

bryanbrunt picture bryanbrunt  路  22Comments