UNPKG

ts-sql-query

Version:

Type-safe SQL query builder like QueryDSL or JOOQ in Java or Linq in .Net for TypeScript with MariaDB, MySql, Oracle, PostgreSql, Sqlite and SqlServer support.

81 lines (80 loc) 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WithViewImpl = void 0; const ITableOrView_1 = require("../utils/ITableOrView"); const ColumnImpl_1 = require("../internal/ColumnImpl"); const symbols_1 = require("../utils/symbols"); const values_1 = require("../expressions/values"); class WithViewImpl { constructor(sqlBuilder, name, selectData) { // @ts-ignore this.__type = 'with'; this.__sqlBuilder = sqlBuilder; this.__name = name; this.__selectData = selectData; if (selectData.__subSelectUsing) { this.__hasExternalDependencies = selectData.__subSelectUsing.length > 0; } const columns = selectData.__columns; (0, ColumnImpl_1.createColumnsFrom)(sqlBuilder, columns, this, this); } as(as) { const result = new WithViewImpl(this.__sqlBuilder, this.__name, this.__selectData); result.__as = as; result.__originalWith = this; return result; } forUseInLeftJoin() { return this.forUseInLeftJoinAs(''); } forUseInLeftJoinAs(as) { const result = new WithViewImpl(this.__sqlBuilder, this.__name, this.__selectData); result.__as = as; result.__forUseInLeftJoin = true; result.__originalWith = this; for (const prop in result) { const column = (0, values_1.__getValueSourceOfObject)(result, prop); if (column) { const columnPrivate = (0, values_1.__getValueSourcePrivate)(column); if (columnPrivate.__optionalType === 'required') { columnPrivate.__optionalType = 'originallyRequired'; } } } return result; } __addWiths(sqlBuilder, withs) { if (this.__ignoreWith) { return; } if (this.__originalWith) { this.__originalWith.__addWiths(sqlBuilder, withs); } else if (!withs.includes(this)) { const withViews = this.__selectData.__withs; for (let i = 0, length = withViews.length; i < length; i++) { const withView = withViews[i]; (0, ITableOrView_1.__getTableOrViewPrivate)(withView).__addWiths(sqlBuilder, withs); } withs.push(this); } (0, ITableOrView_1.__addWiths)(this.__template, sqlBuilder, withs); } __registerTableOrView(sqlBuilder, requiredTablesOrViews) { requiredTablesOrViews.add(this); (0, ITableOrView_1.__registerTableOrView)(this.__template, sqlBuilder, requiredTablesOrViews); } __registerRequiredColumn(sqlBuilder, requiredColumns, onlyForTablesOrViews) { (0, ITableOrView_1.__registerRequiredColumn)(this.__template, sqlBuilder, requiredColumns, onlyForTablesOrViews); } __getOldValues(_sqlBuilder) { return undefined; } __getValuesForInsert(_sqlBuilder) { return undefined; } __isAllowed(_sqlBuilder) { return true; } } exports.WithViewImpl = WithViewImpl;