UNPKG

@sqb/builder

Version:

Extensible multi-dialect SQL query builder written with TypeScript

36 lines (35 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TableName = void 0; const enums_js_1 = require("../enums.js"); const serializable_js_1 = require("../serializable.js"); class TableName extends serializable_js_1.Serializable { schema; table; alias; constructor(tableName) { super(); const m = tableName.match(/^(?:([a-zA-Z][\w$]*)\.)? *([a-zA-Z][\w$]*) *(?:as)? *(\w+)?$/); if (!m) throw new TypeError(`(${tableName}) does not match table name format`); if (m[1]) this.schema = m[1]; if (m[2]) this.table = m[2]; if (m[3]) this.alias = m[3]; } get _type() { return enums_js_1.SerializationType.TABLE_NAME; } _serialize(ctx) { return ctx.serialize(this._type, { schema: this.schema, table: this.table, alias: this.alias, }, () => (this.schema ? this.schema + '.' : '') + this.table + (this.alias ? ' ' + this.alias : '')); } } exports.TableName = TableName;