UNPKG

@jakub.knejzlik/ts-query

Version:

TypeScript implementation of SQL builder

45 lines (44 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateTableAsSelect = void 0; const Query_1 = require("./Query"); const mysql_1 = require("./flavors/mysql"); const interfaces_1 = require("./interfaces"); class CreateTableAsSelect { constructor(_tableName, _select) { this._tableName = _tableName; this._select = _select; } clone() { return new this.constructor(this._tableName, this._select.clone()); } getOperationType() { return interfaces_1.MetadataOperationType.CREATE_TABLE_AS; } getTableNames() { return [this._tableName, ...this._select.getTableNames()]; } toSQL(flavor = new mysql_1.MySQLFlavor()) { return `CREATE TABLE ${flavor.escapeTable(this._tableName)} AS ${this._select.toSQL(flavor)}`; } serialize() { return JSON.stringify(this.toJSON()); } toJSON() { return { type: interfaces_1.OperationType.CREATE_TABLE_AS, select: this._select.toJSON(), tableName: this._tableName, }; } static fromJSON({ tableName, select }) { return new CreateTableAsSelect(tableName, Query_1.SelectQuery.fromJSON(select)); } getTableName() { return this._tableName; } getSelect() { return this._select; } } exports.CreateTableAsSelect = CreateTableAsSelect;