@sqb/builder
Version:
Extensible multi-dialect SQL query builder written with TypeScript
37 lines (36 loc) • 1.11 kB
JavaScript
import { OperatorType } from '../../enums.js';
import { CompOperator } from './comp-operator.js';
export class OpBetween extends CompOperator {
constructor(left, right) {
super(left, right);
this._operatorType = OperatorType.between;
this._symbol = 'between';
if (right && right[1] == null)
right[1] = right[0];
}
_serialize(ctx) {
if (!(this._right && this._right.length > 0))
return '';
const left = this.__serializeItem(ctx, this._left);
const right = [
this.__serializeItem(ctx, this._right[0], true),
this.__serializeItem(ctx, this._right[1], true),
];
const o = {
operatorType: this._operatorType,
symbol: this._symbol,
left,
right,
};
return this.__serialize(ctx, o);
}
__defaultSerialize(ctx, o) {
return (o.left.expression +
' ' +
o.symbol +
' ' +
o.right[0].expression +
' and ' +
o.right[1].expression);
}
}