2023-11-10 09:58:58 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('executeFunc', {
|
|
|
|
description: 'Return result of function',
|
|
|
|
accessType: '*',
|
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'routine',
|
|
|
|
type: 'string',
|
|
|
|
description: 'The routine name',
|
|
|
|
required: true,
|
|
|
|
http: {source: 'path'}
|
|
|
|
},
|
2023-11-14 08:17:46 +00:00
|
|
|
{
|
|
|
|
arg: 'schema',
|
|
|
|
type: 'string',
|
|
|
|
description: 'The routine schema',
|
|
|
|
required: true,
|
|
|
|
},
|
2023-11-10 09:58:58 +00:00
|
|
|
{
|
|
|
|
arg: 'params',
|
|
|
|
type: ['any'],
|
|
|
|
description: 'The params array',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
returns: {
|
|
|
|
type: 'any',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:routine/execute-func`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-14 08:17:46 +00:00
|
|
|
Self.executeFunc = async(ctx, routine, schema, params, options) => {
|
|
|
|
const query = `SELECT ${schema}.${routine}`;
|
2023-11-13 08:36:20 +00:00
|
|
|
|
2023-11-14 08:17:46 +00:00
|
|
|
const response = await Self.execute(ctx, 'FUNCTION', query, params, options);
|
2023-11-10 09:58:58 +00:00
|
|
|
return Object.values(response)[0];
|
|
|
|
};
|
|
|
|
};
|