budibase/packages/server/src/integrations/dynamodb.js

80 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-11-26 17:46:36 +01:00
const AWS = require("aws-sdk")
2021-01-11 18:18:22 +01:00
const SCHEMA = {
datasource: {
table: {
type: "string",
required: true,
},
region: {
type: "string",
required: true,
default: "us-east-1",
},
accessKeyId: {
type: "string",
required: true,
},
secretKey: {
type: "secretKey",
required: true,
default: 5432,
},
indexName: {
type: "string",
},
2020-11-26 17:46:36 +01:00
},
2021-01-11 18:18:22 +01:00
query: {
type: "fields",
fields: [
{
name: "Index",
key: "Index",
type: "string",
},
{
name: "Key Condition Expression",
key: "KeyConditionExpression",
type: "string",
},
{
name: "Attribute Names",
key: "ExpressionAttributeNames",
type: "string",
},
{
name: "Attribute Values",
key: "ExpressionAttributeValues",
type: "string",
},
],
2020-11-26 17:46:36 +01:00
},
}
class DynamoDBIntegration {
constructor(config) {
this.config = config
this.connect()
this.client = new AWS.DynamoDB.DocumentClient()
}
async connect() {
AWS.config.update(this.config)
}
async query() {
const response = await this.client.query({
TableName: this.config.table,
2021-01-11 18:18:22 +01:00
KeyConditionExpression: this.config.KeyConditionExpression,
ExpressionAttributeNames: this.config.ExpressionAttributeNames,
ExpressionAttributeValues: this.config.ExpressionAttributeValues,
2020-11-26 17:46:36 +01:00
})
return response
}
}
module.exports = {
2021-01-11 18:18:22 +01:00
schema: SCHEMA,
2020-11-26 17:46:36 +01:00
integration: DynamoDBIntegration,
}