rawsql-ts
Version:
[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
104 lines • 4.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MergeQuery = exports.MergeWhenClause = exports.MergeDoNothingAction = exports.MergeInsertAction = exports.MergeDeleteAction = exports.MergeUpdateAction = exports.MergeAction = void 0;
const SqlComponent_1 = require("./SqlComponent");
const ValueComponent_1 = require("./ValueComponent");
const Clause_1 = require("./Clause");
class MergeAction extends SqlComponent_1.SqlComponent {
}
exports.MergeAction = MergeAction;
MergeAction.kind = Symbol("MergeAction");
class MergeUpdateAction extends MergeAction {
constructor(setClause, whereClause) {
super();
this.setClause = setClause instanceof Clause_1.SetClause ? setClause : new Clause_1.SetClause(setClause);
this.whereClause = whereClause !== null && whereClause !== void 0 ? whereClause : null;
}
}
exports.MergeUpdateAction = MergeUpdateAction;
MergeUpdateAction.kind = Symbol("MergeUpdateAction");
class MergeDeleteAction extends MergeAction {
constructor(whereClause) {
super();
this.whereClause = whereClause !== null && whereClause !== void 0 ? whereClause : null;
}
}
exports.MergeDeleteAction = MergeDeleteAction;
MergeDeleteAction.kind = Symbol("MergeDeleteAction");
class MergeInsertAction extends MergeAction {
constructor(params) {
var _a, _b;
super();
this.columns = params.columns
? params.columns.map(col => (typeof col === "string" ? new ValueComponent_1.IdentifierString(col) : col))
: null;
this.values = (_a = params.values) !== null && _a !== void 0 ? _a : null;
this.defaultValues = (_b = params.defaultValues) !== null && _b !== void 0 ? _b : false;
this.valuesLeadingComments = params.valuesLeadingComments ? [...params.valuesLeadingComments] : null;
}
addValuesLeadingComments(comments) {
if (!comments || comments.length === 0) {
return;
}
if (!this.valuesLeadingComments) {
this.valuesLeadingComments = [];
}
for (const comment of comments) {
if (!this.valuesLeadingComments.includes(comment)) {
this.valuesLeadingComments.push(comment);
}
}
}
getValuesLeadingComments() {
return this.valuesLeadingComments ? [...this.valuesLeadingComments] : [];
}
}
exports.MergeInsertAction = MergeInsertAction;
MergeInsertAction.kind = Symbol("MergeInsertAction");
class MergeDoNothingAction extends MergeAction {
}
exports.MergeDoNothingAction = MergeDoNothingAction;
MergeDoNothingAction.kind = Symbol("MergeDoNothingAction");
class MergeWhenClause extends SqlComponent_1.SqlComponent {
constructor(matchType, action, condition, options) {
super();
this.matchType = matchType;
this.action = action;
this.condition = condition !== null && condition !== void 0 ? condition : null;
this.thenLeadingComments = (options === null || options === void 0 ? void 0 : options.thenLeadingComments)
? [...options.thenLeadingComments]
: null;
}
addThenLeadingComments(comments) {
if (!comments || comments.length === 0) {
return;
}
if (!this.thenLeadingComments) {
this.thenLeadingComments = [];
}
for (const comment of comments) {
if (!this.thenLeadingComments.includes(comment)) {
this.thenLeadingComments.push(comment);
}
}
}
getThenLeadingComments() {
return this.thenLeadingComments ? [...this.thenLeadingComments] : [];
}
}
exports.MergeWhenClause = MergeWhenClause;
MergeWhenClause.kind = Symbol("MergeWhenClause");
class MergeQuery extends SqlComponent_1.SqlComponent {
constructor(params) {
var _a;
super();
this.withClause = (_a = params.withClause) !== null && _a !== void 0 ? _a : null;
this.target = params.target;
this.source = params.source;
this.onCondition = params.onCondition;
this.whenClauses = params.whenClauses;
}
}
exports.MergeQuery = MergeQuery;
MergeQuery.kind = Symbol("MergeQuery");
//# sourceMappingURL=MergeQuery.js.map