UNPKG

rawsql-ts

Version:

High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

94 lines 3.62 kB
import { SqlComponent } from "./SqlComponent"; import { IdentifierString } from "./ValueComponent"; import { SetClause } from "./Clause"; export class MergeAction extends SqlComponent { } MergeAction.kind = Symbol("MergeAction"); export class MergeUpdateAction extends MergeAction { constructor(setClause, whereClause) { super(); this.setClause = setClause instanceof SetClause ? setClause : new SetClause(setClause); this.whereClause = whereClause !== null && whereClause !== void 0 ? whereClause : null; } } MergeUpdateAction.kind = Symbol("MergeUpdateAction"); export class MergeDeleteAction extends MergeAction { constructor(whereClause) { super(); this.whereClause = whereClause !== null && whereClause !== void 0 ? whereClause : null; } } MergeDeleteAction.kind = Symbol("MergeDeleteAction"); export class MergeInsertAction extends MergeAction { constructor(params) { var _a, _b; super(); this.columns = params.columns ? params.columns.map(col => (typeof col === "string" ? new 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] : []; } } MergeInsertAction.kind = Symbol("MergeInsertAction"); export class MergeDoNothingAction extends MergeAction { } MergeDoNothingAction.kind = Symbol("MergeDoNothingAction"); export class MergeWhenClause extends 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] : []; } } MergeWhenClause.kind = Symbol("MergeWhenClause"); export class MergeQuery extends 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; } } MergeQuery.kind = Symbol("MergeQuery"); //# sourceMappingURL=MergeQuery.js.map