Skip to content

Querier

A querier is the @uql/core’s abstraction over database drivers to dynamically generate the queries for any given entity. It allows interaction with the different databases in a consistent way.

With a querier you can:

  • Manipulate the data related to any entity.
  • Use [declarative]/transactions-declarative) and [imperative]/transactions-imperative) transactions.
  • Obtain repositories for specific entities.
import { User } from './shared/models/index.js';
import { pool } from './shared/orm.js';
// Obtain a querier from the pool
const querier = await pool.getQuerier();
try {
const users = await querier.findMany(
User,
{
$select: ['id'],
$where: { $or: [{ name: 'roger' }, { creatorId: 1 }] },
}
);
} finally {
// IMPORTANT: Always release the querier to return the connection to the pool
await querier.release();
}