@sqb/builder
Version:
Extensible multi-dialect SQL query builder written with TypeScript
29 lines (28 loc) • 916 B
JavaScript
import { SerializationType } from '../enums.js';
import { Serializable } from '../serializable.js';
export class TableName extends Serializable {
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 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 : ''));
}
}