1
0
Fork 0
mirror of synced 2024-09-21 11:53:49 +12:00
budibase/packages/server/src/automations/steps/executeQuery.js

85 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-27 03:56:34 +13:00
const queryController = require("../../api/controllers/query")
module.exports.definition = {
name: "External Data Connector",
tagline: "Execute Data Connector",
icon: "ri-database-2-line",
description: "Execute a query in an external data connector",
type: "ACTION",
stepId: "EXECUTE_QUERY",
inputs: {},
schema: {
inputs: {
properties: {
query: {
type: "object",
2021-04-30 08:35:16 +12:00
properties: {
queryId: {
type: "string",
customType: "query",
},
},
customType: "queryParams",
title: "Parameters",
required: ["queryId"],
2021-03-27 03:56:34 +13:00
},
},
2021-04-30 08:35:16 +12:00
required: ["query"],
2021-03-27 03:56:34 +13:00
},
outputs: {
properties: {
response: {
type: "object",
description: "The response from the datasource execution",
},
success: {
type: "boolean",
description: "Whether the action was successful",
},
},
},
required: ["response", "success"],
},
}
2021-05-04 20:55:14 +12:00
module.exports.run = async function ({ inputs, appId, emitter }) {
2021-03-27 03:56:34 +13:00
if (inputs.query == null) {
return {
success: false,
response: {
message: "Invalid inputs",
},
}
}
2021-04-30 08:35:16 +12:00
const { queryId, ...rest } = inputs.query
2021-03-27 03:56:34 +13:00
const ctx = {
params: {
2021-04-30 08:35:16 +12:00
queryId,
2021-03-27 03:56:34 +13:00
},
request: {
body: {
2021-04-30 08:35:16 +12:00
parameters: rest,
2021-03-27 03:56:34 +13:00
},
},
2021-04-30 08:35:16 +12:00
appId,
2021-03-27 03:56:34 +13:00
eventEmitter: emitter,
}
await queryController.execute(ctx)
try {
return {
response: ctx.body,
success: ctx.status === 200,
}
} catch (err) {
console.error(err)
return {
success: false,
response: err,
}
}
}