1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat(PostgreSQL): trigger functions support

This commit is contained in:
2021-07-03 11:29:14 +02:00
parent faa07a077c
commit 75bbd5f66e
17 changed files with 747 additions and 6 deletions

View File

@ -215,6 +215,7 @@ export class PostgreSQLClient extends AntaresCore {
functions: [],
procedures: [],
triggers: [],
triggerFunctions: [],
schedulers: []
};
}
@ -822,7 +823,7 @@ export class PostgreSQLClient extends AntaresCore {
if (this._schema !== 'public')
await this.use(this._schema);
const body = func.returns ? func.sql : '$BODY$\n$BODY$';
const body = func.returns ? func.sql : '$function$\n$function$';
const sql = `CREATE FUNCTION ${this._schema}.${func.name}(${parameters})
RETURNS ${func.returns || 'void'}
@ -833,6 +834,48 @@ export class PostgreSQLClient extends AntaresCore {
return await this.raw(sql, { split: false });
}
/**
* ALTER TRIGGER FUNCTION
*
* @returns {Array.<Object>} parameters
* @memberof PostgreSQLClient
*/
async alterTriggerFunction (params) {
const { func } = params;
if (this._schema !== 'public')
await this.use(this._schema);
const body = func.returns ? func.sql : '$function$\n$function$';
const sql = `CREATE OR REPLACE FUNCTION ${this._schema}.${func.name}()
RETURNS TRIGGER
LANGUAGE ${func.language}
AS ${body}`;
return await this.raw(sql, { split: false });
}
/**
* CREATE TRIGGER FUNCTION
*
* @returns {Array.<Object>} parameters
* @memberof PostgreSQLClient
*/
async createTriggerFunction (func) {
if (this._schema !== 'public')
await this.use(this._schema);
const body = func.returns ? func.sql : '$function$\r\nBEGIN\r\n\r\nEND\r\n$function$';
const sql = `CREATE FUNCTION ${this._schema}.${func.name}()
RETURNS TRIGGER
LANGUAGE ${func.language}
AS ${body}`;
return await this.raw(sql, { split: false });
}
/**
* SELECT * FROM pg_collation
*