UNPKG

sedk-postgres

Version:

Simple SQL builder and validator

106 lines 3.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OnOrStep = exports.OnAndStep = exports.OnStep = exports.CrossJoinStep = exports.AfterFromStep = void 0; const BaseStep_1 = require("../BaseStep"); const LimitStep_1 = require("./LimitStep"); const OffsetStep_1 = require("./OffsetStep"); const database_1 = require("../../database"); const SelectConditionStep_1 = require("./SelectConditionStep"); const ReturningStep_1 = require("../ReturningStep"); const BaseJoinStep_1 = require("./BaseJoinStep"); const OrderByStep_1 = require("./OrderByStep"); const GroupByStep_1 = require("./GroupByStep"); class AfterFromStep extends BaseStep_1.BaseStep { crossJoin(fromItem) { return new CrossJoinStep(this, fromItem); } leftJoin(fromItem) { return new BaseJoinStep_1.LeftJoinStep(this, fromItem); } rightJoin(fromItem) { return new BaseJoinStep_1.RightJoinStep(this, fromItem); } fullOuterJoin(fromItem) { return new BaseJoinStep_1.FullOuterJoinStep(this, fromItem); } innerJoin(fromItem) { return new BaseJoinStep_1.InnerJoinStep(this, fromItem); } join(fromItem) { return new BaseJoinStep_1.JoinStep(this, fromItem); } where(condition, operator, middle, operator2, right) { const whereParts = []; BaseStep_1.BaseStep.addConditionParts(whereParts, condition, operator, middle, operator2, right); return new SelectConditionStep_1.SelectWhereStep(this, whereParts); } groupBy(...groupByItems) { return new GroupByStep_1.GroupByStep(this, groupByItems); } limit(n) { return new LimitStep_1.LimitStep(this, n); } limit$(n) { return new LimitStep_1.LimitStep(this, n, true); } offset(n) { return new OffsetStep_1.OffsetStep(this, n); } offset$(n) { return new OffsetStep_1.OffsetStep(this, n, true); } orderBy(...orderByItems) { return new OrderByStep_1.OrderByStep(this, orderByItems); } // TODO: check if we can limit this to only update, insert and delete returning(...items) { return new ReturningStep_1.ReturningStep(this, items); } } exports.AfterFromStep = AfterFromStep; class CrossJoinStep extends AfterFromStep { constructor(prevStep, fromItem) { super(prevStep); this.fromItem = fromItem; } getStepStatement(artifacts = { tables: new Set(), columns: new Set() }) { return `CROSS JOIN ${this.fromItem.getStmt(this.data, artifacts)}`; } getStepArtifacts() { const table = this.fromItem instanceof database_1.Table ? this.fromItem : this.fromItem.table; return { tables: new Set([table]), columns: new Set() }; } } exports.CrossJoinStep = CrossJoinStep; class OnStep extends AfterFromStep { constructor(prevStep, condition) { super(prevStep); this.condition = condition; } getStepStatement(artifacts = { tables: new Set(), columns: new Set() }) { return `ON ${this.condition.getStmt(this.data, artifacts, this.binderStore)}`; } getStepArtifacts() { return { tables: new Set(), columns: new Set(this.condition.getColumns()) }; } or(condition) { return new OnOrStep(this, condition); } and(condition) { return new OnAndStep(this, condition); } } exports.OnStep = OnStep; class OnAndStep extends OnStep { getStepStatement(artifacts = { tables: new Set(), columns: new Set() }) { return `AND ${this.condition.getStmt(this.data, artifacts, this.binderStore)}`; } } exports.OnAndStep = OnAndStep; class OnOrStep extends OnStep { getStepStatement(artifacts = { tables: new Set(), columns: new Set() }) { return `OR ${this.condition.getStmt(this.data, artifacts, this.binderStore)}`; } } exports.OnOrStep = OnOrStep; //# sourceMappingURL=AfterFromStep.js.map