All files / src eq.ts

90.9% Statements 10/11
100% Branches 4/4
100% Functions 2/2
90% Lines 9/10

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 2922x 22x 22x 22x       22x 53x                           22x 64x       85x  
import fallback from './fallback.js'
import id from './identifier.js'
import isNull from './is-null.js'
import tsql from './template.js'
import type S from './sanitised.js'
 
const rhsEq =
  (rhs: unknown): S =>
    isNull(rhs) ?
      tsql`is null` :
      tsql`= ${rhs}`
 
/**
 * @returns comparision expression.
 *
 * `null` RHS returns LHS IS NULL.
 *
 * `undefined` RHS propagates.
 *
 * @see distinct for NULL aware comparision.
 */
export const eq =
  (lhs: S | string, rhs: unknown): undefined | S =>
    typeof rhs === 'undefined' ?
      undefined :
      tsql`${fallback(lhs, id)} ${rhsEq(rhs)}`
 
export default eq