All files / src/expressions logic.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                            131x                             131x      
import type { WhereOptions } from '../model/where-options.ts';
import { Op } from './op.ts';
 
/**
 * Combines conditions with `AND` (Sequelize v6 `and`), for use inside `where`.
 *
 * @param conditions - Conditions to combine.
 * @returns A `{ [Op.and]: conditions }` condition usable as `where`.
 *
 * @example
 * ```ts
 * await User.findAll({ where: and({ age: { [Op.gt]: 18 } }, { active: true }) });
 * ```
 */
export const and = (...conditions: readonly WhereOptions[]): WhereOptions => ({
  [Op.and]: conditions,
});
 
/**
 * Combines conditions with `OR` (Sequelize v6 `or`), for use inside `where`.
 *
 * @param conditions - Conditions to combine.
 * @returns A `{ [Op.or]: conditions }` condition usable as `where`.
 *
 * @example
 * ```ts
 * await User.findAll({ where: or({ role: 'admin' }, { role: 'owner' }) });
 * ```
 */
export const or = (...conditions: readonly WhereOptions[]): WhereOptions => ({
  [Op.or]: conditions,
});