mirror of https://github.com/Budibase/budibase.git
11 changed files with 293 additions and 51 deletions
@ -1,7 +0,0 @@ |
|||
class Integration { |
|||
definition() { |
|||
return this.options |
|||
} |
|||
} |
|||
|
|||
module.exports = Integration |
|||
@ -0,0 +1,64 @@ |
|||
const AWS = require("aws-sdk") |
|||
|
|||
const DYNAMODB_OPTIONS = { |
|||
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", |
|||
}, |
|||
keyConditionExpression: { |
|||
type: "string", |
|||
required: true, |
|||
}, |
|||
attributeNames: { |
|||
type: "object", |
|||
required: true, |
|||
}, |
|||
attributeValues: { |
|||
type: "object", |
|||
required: true, |
|||
}, |
|||
} |
|||
|
|||
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, |
|||
KeyConditionExpression: this.config.keyConditionExpression, |
|||
ExpressionAttributeNames: this.config.attributeNames, |
|||
ExpressionAttributeValues: this.config.attributeValues, |
|||
}) |
|||
return response |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
schema: DYNAMODB_OPTIONS, |
|||
integration: DynamoDBIntegration, |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
const { MongoClient } = require("mongodb") |
|||
|
|||
const MONGODB_OPTIONS = { |
|||
connectionString: { |
|||
type: "string", |
|||
required: true, |
|||
default: "localhost", |
|||
}, |
|||
db: { |
|||
type: "string", |
|||
required: true, |
|||
}, |
|||
collection: { |
|||
type: "string", |
|||
required: true, |
|||
}, |
|||
query: { |
|||
type: "query", |
|||
required: true, |
|||
}, |
|||
} |
|||
|
|||
class MongoIntegration { |
|||
constructor(config) { |
|||
this.config = config |
|||
this.client = new MongoClient(config.connectionString) |
|||
} |
|||
|
|||
async connect() { |
|||
return this.client.connect() |
|||
} |
|||
|
|||
async query() { |
|||
try { |
|||
await this.connect() |
|||
const db = this.client.db(this.config.db) |
|||
const collection = db.collection(this.config.collection) |
|||
const result = await collection.find(this.config.query).toArray() |
|||
return result |
|||
} finally { |
|||
await this.client.close() |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
schema: MONGODB_OPTIONS, |
|||
integration: MongoIntegration, |
|||
} |
|||
Loading…
Reference in new issue