@sqb/builder
Version:
Extensible multi-dialect SQL query builder written with TypeScript
28 lines (27 loc) • 908 B
JavaScript
import { OperatorType } from '../../enums.js';
import { isSelectQuery } from '../../typeguards.js';
import { CompOperator } from './comp-operator.js';
export class OpExists extends CompOperator {
_operatorType = OperatorType.exists;
_symbol = 'exists';
constructor(query) {
super(query);
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 : '';
}
}