How to add NOLOCK for Auto generated SQL queries in Loopback 3

156 Views Asked by At

I'm using Loopback 3 and SQL. We've 20 million rows in SQL tables and when we query data using Loopback it's taking a lot of time and further observation we found queries are blocking in SQL. Noticed that the Loopback auto generated queries doesn't have any WITH (NOLOCK). How to add WITH (NOLOCK) for every SELECT query?

1

There are 1 best solutions below

4
On

Using Transaction.READ_UNCOMMITTED would produce WITH (NOLOCK).

For example:

YourModel.beginTransaction({isolationLevel: YourModel.Transaction.READ_UNCOMMITTED}, (err, tx) => {
  // Now we have a transaction (tx)
  // Write the queries here
  // Then run commit the transaction:
  tx.commit(err => {});
});

See the docs for more details.