UNPKG

ddl-manager

Version:

store postgres procedures and triggers in files

92 lines 3.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheSyntax = void 0; const psql_lang_1 = require("psql-lang"); const CacheOption_1 = require("./CacheOption"); const CacheIndex_1 = require("./CacheIndex"); const CacheWithoutInsertOn_1 = require("./CacheWithoutInsertOn"); const CacheWithoutTriggersOn_1 = require("./CacheWithoutTriggersOn"); class CacheSyntax extends psql_lang_1.AbstractScopeNode { static entry(cursor) { return cursor.beforeWord("cache"); } static parse(cursor) { cursor.skipSpaces(); cursor.readWord("cache"); const name = cursor.parse(psql_lang_1.Name); cursor.skipSpaces(); cursor.readWord("for"); const destinationTable = cursor.parse(psql_lang_1.TableReference); cursor.skipSpaces(); const alias = this.parseAlias(cursor); cursor.skipSpaces(); cursor.readValue("("); cursor.skipSpaces(); const cacheSelect = cursor.parse(psql_lang_1.Select); cursor.skipSpaces(); cursor.readValue(")"); cursor.skipSpaces(); const options = this.parseOptions(cursor); return Object.assign({ name, for: destinationTable, as: alias, cache: cacheSelect }, options); } static parseAlias(cursor) { if (!cursor.beforeWord("as")) { return; } cursor.readWord("as"); return cursor.parse(psql_lang_1.Name); } static parseOptions(cursor) { if (!cursor.before(CacheOption_1.CacheOption)) { return {}; } const indexes = []; const withoutInsertOn = []; const withoutTriggersOn = []; const optionsNodes = cursor.parseChainOf(CacheOption_1.CacheOption); for (const optionNode of optionsNodes) { const option = optionNode.row.option; if (option instanceof CacheIndex_1.CacheIndex) { indexes.push(option); } if (option instanceof CacheWithoutInsertOn_1.CacheWithoutInsertOn) { withoutInsertOn.push(option.row.withoutInsertOn); } if (option instanceof CacheWithoutTriggersOn_1.CacheWithoutTriggersOn) { withoutTriggersOn.push(option.row.withoutTriggersOn); } } return { indexes, withoutInsertOn, withoutTriggersOn }; } hasClojure() { return true; } template() { const cache = this.row; const select = this.row.cache; const output = [ psql_lang_1.keyword("cache"), cache.name, psql_lang_1.keyword("for"), cache.for ]; if (cache.as) { output.push(psql_lang_1.keyword("as"), cache.as); } output.push("(", psql_lang_1.eol); output.push(select, psql_lang_1.eol); output.push(")"); for (const withoutInsertOn of cache.withoutInsertOn || []) { const node = new CacheWithoutInsertOn_1.CacheWithoutInsertOn({ row: { withoutInsertOn } }); output.push(node, psql_lang_1.eol); } for (const withoutTriggersOn of cache.withoutTriggersOn || []) { const node = new CacheWithoutTriggersOn_1.CacheWithoutTriggersOn({ row: { withoutTriggersOn } }); output.push(node, psql_lang_1.eol); } for (const index of cache.indexes || []) { output.push(index, psql_lang_1.eol); } return output; } } exports.CacheSyntax = CacheSyntax; //# sourceMappingURL=CacheSyntax.js.map