@sqb/builder
Version:
Extensible multi-dialect SQL query builder written with TypeScript
51 lines (50 loc) • 1.23 kB
JavaScript
import { SerializationType } from '../enums.js';
import { Serializable } from '../serializable.js';
export class SequenceGetterStatement extends Serializable {
_expression;
_next;
_alias;
constructor(expression, next) {
super();
this._expression = expression;
this._next = !!next;
}
get _type() {
return SerializationType.SEQUENCE_GETTER_STATEMENT;
}
next(value) {
this._next = value;
return this;
}
/**
* Sets alias to case expression.
*/
as(alias) {
this._alias = alias;
return this;
}
/**
* Performs serialization
*
* @param {Object} ctx
* @return {string}
* @override
*/
_serialize(ctx) {
if (!this._expression)
return '';
const q = {
genName: this._expression,
next: this._next,
alias: this._alias,
};
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
}
__defaultSerialize(ctx, o) {
return ((o.next ? 'nextval' : 'currval') +
"('" +
o.genName +
"')" +
(o.alias ? ' ' + o.alias : ''));
}
}