ddl-manager
Version:
store postgres procedures and triggers in files
60 lines • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSyntax = void 0;
const psql_lang_1 = require("psql-lang");
const CacheSyntax_1 = require("./CacheSyntax");
const CacheLinter_1 = require("./CacheLinter");
const CommentSyntax_1 = require("./CommentSyntax");
class FileSyntax extends psql_lang_1.AbstractNode {
static entry(cursor) {
return (cursor.before(psql_lang_1.CreateFunction) ||
cursor.before(psql_lang_1.CreateTrigger) ||
cursor.before(CacheSyntax_1.CacheSyntax));
}
static parse(cursor) {
const output = {
functions: [],
triggers: [],
caches: []
};
while (!cursor.beforeEnd()) {
this.parseDelimiters(cursor);
if (cursor.before(psql_lang_1.CreateFunction)) {
const function_ = cursor.parse(psql_lang_1.CreateFunction);
output.functions.push(function_);
}
else if (cursor.before(psql_lang_1.CreateTrigger)) {
const trigger = cursor.parse(psql_lang_1.CreateTrigger);
output.triggers.push(trigger);
}
else if (cursor.before(CacheSyntax_1.CacheSyntax)) {
const cache = cursor.parse(CacheSyntax_1.CacheSyntax);
CacheLinter_1.CacheLinter.lint(cursor, cache);
output.caches.push(cache);
}
else if (cursor.before(CommentSyntax_1.CommentSyntax)) {
cursor.parse(CommentSyntax_1.CommentSyntax); // just ignore
}
else if (!cursor.beforeEnd()) {
cursor.throwError("expected function or trigger or cache");
}
}
return output;
}
static parseDelimiters(cursor) {
cursor.skipSpaces();
while (cursor.beforeValue(";")) {
cursor.readValue(";");
cursor.skipSpaces();
}
}
template() {
return [
...this.row.functions,
...this.row.triggers,
...this.row.caches,
];
}
}
exports.FileSyntax = FileSyntax;
//# sourceMappingURL=FileSyntax.js.map