dynamo integration

This commit is contained in:
Martin McKeaveney 2021-01-15 13:24:36 +00:00
parent 6f57c1d22d
commit 4442240e68
2 changed files with 64 additions and 9 deletions

View File

@ -50,7 +50,7 @@
<Spacer medium /> <Spacer medium />
{#if query} {#if query?.parameters.length > 0}
<ParameterBuilder <ParameterBuilder
bind:customParams={parameters.queryParams} bind:customParams={parameters.queryParams}
parameters={query.parameters} parameters={query.parameters}

View File

@ -18,25 +18,56 @@ const SCHEMA = {
}, },
}, },
query: { query: {
create: {
DynamoConfig: {
type: QUERY_TYPES.FIELDS,
fields: {
table: {
type: FIELD_TYPES.STRING,
required: true,
},
customisable: true,
},
},
},
read: { read: {
DynamoConfig: { DynamoConfig: {
type: QUERY_TYPES.FIELDS, type: QUERY_TYPES.FIELDS,
fields: { fields: {
Table: { table: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
required: true, required: true,
}, },
Index: { index: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
}, },
KeyConditionExpression: { customisable: true,
},
},
},
update: {
DynamoConfig: {
type: QUERY_TYPES.FIELDS,
fields: {
table: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
required: true,
}, },
ExpressionAttributeNames: { customisable: true,
},
},
},
delete: {
"Dynamo Partition Key": {
type: QUERY_TYPES.FIELDS,
fields: {
table: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
required: true,
}, },
ExpressionAttributeValues: { key: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
required: true,
}, },
}, },
}, },
@ -55,12 +86,36 @@ class DynamoDBIntegration {
AWS.config.update(this.config) AWS.config.update(this.config)
} }
async create(query) {
const response = await this.client.query({
TableName: query.table,
Item: query.json,
})
return response
}
async read(query) { async read(query) {
const response = await this.client.query({ const response = await this.client.query({
TableName: query.Table, TableName: query.Table,
KeyConditionExpression: query.KeyConditionExpression, ...query.json,
ExpressionAttributeNames: query.ExpressionAttributeNames, })
ExpressionAttributeValues: query.ExpressionAttributeValues, return response
}
async update(query) {
const response = await this.client.query({
TableName: query.Table,
...query.json,
})
return response
}
async delete(query) {
const response = await this.client.query({
TableName: query.Table,
Key: {
id: query.key,
},
}) })
return response return response
} }