UNPKG

@sqb/builder

Version:

Extensible multi-dialect SQL query builder written with TypeScript

28 lines (27 loc) 926 B
import { OperatorType } from '../../enums.js'; import { isSelectQuery } from '../../typeguards.js'; import { CompOperator } from './comp-operator.js'; export class OpExists extends CompOperator { constructor(query) { super(query); this._operatorType = OperatorType.exists; this._symbol = 'exists'; if (!(typeof query === 'object' && isSelectQuery(query))) { throw new TypeError('You must provide a SelectQuery in `exists()`'); } } _serialize(ctx) { const left = this.__serializeItem(ctx, this._left); if (this._isArray) left.isArray = true; const o = { operatorType: this._operatorType, symbol: this._symbol, left, }; return this.__serialize(ctx, o); } __defaultSerialize(ctx, o) { return o.left.expression ? o.symbol + ' ' + o.left.expression : ''; } }