UNPKG

@sqb/builder

Version:

Extensible multi-dialect SQL query builder written with TypeScript

37 lines (36 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupColumn = void 0; const enums_js_1 = require("../enums.js"); const base_field_js_1 = require("./base-field.js"); const GROUP_COLUMN_PATTERN = /^((?:[a-zA-Z][\w$]*\.){0,2})([\w$]*)$/; class GroupColumn extends base_field_js_1.BaseField { constructor(value) { super(); const m = value.match(GROUP_COLUMN_PATTERN); if (!m) throw new TypeError(`"${value}" does not match group column format`); this._field = m[2]; if (m[1]) { const a = m[1].split(/\./g); a.pop(); this._table = a.pop(); this._schema = a.pop(); } } get _type() { return enums_js_1.SerializationType.GROUP_COLUMN; } _serialize(ctx) { const o = { schema: this._schema, table: this._table, field: this._field, isReservedWord: !!(this._field && ctx.isReservedWord(this._field)), }; return ctx.serialize(this._type, o, () => (this._schema ? this._schema + '.' : '') + (this._table ? this._table + '.' : '') + (o.isReservedWord ? '"' + this._field + '"' : this._field)); } } exports.GroupColumn = GroupColumn;