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:
@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user