UNPKG

@sequeljs/ast

Version:

A SQL AST manager for JavaScript

127 lines 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const SelectStatement_1 = require("../nodes/SelectStatement"); const ToSQL_1 = require("./ToSQL"); class PostgreSQL extends ToSQL_1.default { groupingArrayOrGroupingElement(thing, col) { let collector = col; if (Array.isArray(thing.expr)) { collector.append('( '); collector = this.visit(thing.expr, collector); collector.append(' )'); } else { collector = this.visit(thing.expr, collector); } return collector; } groupingParentheses(thing, col) { let collector = col; if (thing.expr instanceof SelectStatement_1.default) { collector.append('('); collector = this.visit(thing.expr, collector); collector.append(')'); } else { collector = this.visit(thing.expr, collector); } return collector; } visitBindParam(thing, col) { let collector = col; collector = collector.addBind(thing.value, (i) => `$${i}`); return collector; } visitCube(thing, col) { let collector = col; collector.append('CUBE'); collector = this.groupingArrayOrGroupingElement(thing, collector); return collector; } visitDistinctOn(thing, col) { let collector = col; collector.append('DISTINCT ON ( '); collector = this.visit(thing.expr, collector); collector.append(' )'); return collector; } visitDoesNotMatch(thing, col) { let collector = col; const op = thing.caseSensitive ? ' NOT LIKE ' : ' NOT ILIKE '; collector = this.infixValue(thing, collector, op); if (thing.escape) { collector.append(' ESCAPE '); collector = this.visit(thing.escape, collector); } return collector; } visitGroupingElement(thing, col) { let collector = col; collector.append('( '); collector = this.visit(thing.expr, collector); collector.append(' )'); return collector; } visitGroupingSet(thing, col) { let collector = col; collector.append('GROUPING SETS'); collector = this.groupingArrayOrGroupingElement(thing, collector); return collector; } visitIsDistinctFrom(thing, col) { let collector = col; collector = this.visit(thing.left, collector); collector.append(' IS DISTINCT FROM '); collector = this.visit(thing.right, collector); return collector; } visitIsNotDistinctFrom(thing, col) { let collector = col; collector = this.visit(thing.left, collector); collector.append(' IS NOT DISTINCT FROM '); collector = this.visit(thing.right, collector); return collector; } visitLateral(thing, col) { let collector = col; collector.append('LATERAL '); collector = this.groupingParentheses(thing, collector); return collector; } visitMatches(thing, col) { let collector = col; const op = thing.caseSensitive ? ' LIKE ' : ' ILIKE '; collector = this.infixValue(thing, collector, op); if (thing.escape) { collector.append(' ESCAPE '); collector = this.visit(thing.escape, collector); } return collector; } visitNotRegexp(thing, col) { let collector = col; const op = thing.caseSensitive ? ' !~ ' : ' !~* '; collector = this.infixValue(thing, collector, op); return collector; } visitNullsFirst(thing, col) { return this.visit(thing.expr, col).append(' NULLS FIRST'); } visitNullsLast(thing, col) { return this.visit(thing.expr, col).append(' NULLS LAST'); } visitRegexp(thing, col) { let collector = col; const op = thing.caseSensitive ? ' ~ ' : ' ~* '; collector = this.infixValue(thing, collector, op); return collector; } visitRollUp(thing, col) { let collector = col; collector.append('ROLLUP'); collector = this.groupingArrayOrGroupingElement(thing, collector); return collector; } } exports.default = PostgreSQL; //# sourceMappingURL=PostgreSQL.js.map