Adding cleanup operation to dynamo client.
This commit is contained in:
parent
806bd4e06b
commit
2ef1586d4d
|
@ -116,9 +116,8 @@ exports.preview = async function(ctx) {
|
||||||
|
|
||||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||||
|
|
||||||
const rows = formatResponse(
|
const integration = new Integration(datasource.config)
|
||||||
await new Integration(datasource.config)[queryVerb](enrichedQuery)
|
const rows = formatResponse(await integration[queryVerb](enrichedQuery))
|
||||||
)
|
|
||||||
|
|
||||||
// get all the potential fields in the schema
|
// get all the potential fields in the schema
|
||||||
const keys = rows.flatMap(Object.keys)
|
const keys = rows.flatMap(Object.keys)
|
||||||
|
@ -127,6 +126,10 @@ exports.preview = async function(ctx) {
|
||||||
rows,
|
rows,
|
||||||
schemaFields: [...new Set(keys)],
|
schemaFields: [...new Set(keys)],
|
||||||
}
|
}
|
||||||
|
// cleanup
|
||||||
|
if (integration.end) {
|
||||||
|
integration.end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.execute = async function(ctx) {
|
exports.execute = async function(ctx) {
|
||||||
|
@ -146,10 +149,13 @@ exports.execute = async function(ctx) {
|
||||||
ctx.request.body.parameters
|
ctx.request.body.parameters
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const integration = new Integration(datasource.config)
|
||||||
// call the relevant CRUD method on the integration class
|
// call the relevant CRUD method on the integration class
|
||||||
ctx.body = formatResponse(
|
ctx.body = formatResponse(await integration[query.queryVerb](enrichedQuery))
|
||||||
await new Integration(datasource.config)[query.queryVerb](enrichedQuery)
|
// cleanup
|
||||||
)
|
if (integration.end) {
|
||||||
|
integration.end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async function(ctx) {
|
exports.destroy = async function(ctx) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ let _ = require("lodash")
|
||||||
let env = require("../environment")
|
let env = require("../environment")
|
||||||
|
|
||||||
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
||||||
|
exports.AWS_REGION = AWS_REGION
|
||||||
|
|
||||||
const TableInfo = {
|
const TableInfo = {
|
||||||
API_KEYS: {
|
API_KEYS: {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const AWS = require("aws-sdk")
|
const AWS = require("aws-sdk")
|
||||||
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
|
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
|
||||||
|
const { AWS_REGION } = require("../db/dynamoClient")
|
||||||
|
|
||||||
const SCHEMA = {
|
const SCHEMA = {
|
||||||
docs: "https://github.com/dabit3/dynamodb-documentclient-cheat-sheet",
|
docs: "https://github.com/dabit3/dynamodb-documentclient-cheat-sheet",
|
||||||
|
@ -114,10 +115,22 @@ class DynamoDBIntegration {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end() {
|
||||||
|
this.disconnect()
|
||||||
|
}
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
AWS.config.update(this.config)
|
AWS.config.update(this.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disconnect() {
|
||||||
|
AWS.config.update({
|
||||||
|
secretAccessKey: undefined,
|
||||||
|
accessKeyId: undefined,
|
||||||
|
region: AWS_REGION,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async create(query) {
|
async create(query) {
|
||||||
const params = {
|
const params = {
|
||||||
TableName: query.table,
|
TableName: query.table,
|
||||||
|
|
Loading…
Reference in New Issue