@winglibs/dynamodb
v0.3.0
Published
DynamoDB library for Wing
Downloads
15,513
Readme
dynamodb
Prerequisites
Installation
npm i @winglibs/dynamodb
Usage
bring dynamodb;
let table = new dynamodb.Table(
attributes: [
{
name: "id",
type: "S",
},
],
hashKey: "id",
);
// Streams.
table.setStreamConsumer(inflight (record) => {
log("record processed = {Json.stringify(record)}");
});
// Put and query.
test "put and query" {
table.put(
Item: {
id: "1",
body: "hello",
},
);
let response = table.query(
KeyConditionExpression: "id = :id",
ExpressionAttributeValues: {":id": "1"},
);
assert(response.Count == 1);
assert(response.Items[0]["id"].asStr() == "1");
assert(response.Items[0]["body"].asStr() == "hello");
}
In case you want to instantiate your own DynamoDB SDK, you can get the connection details like this:
table.connection.clientConfig.endpoint;
table.connection.clientConfig.credentials;
table.connection.clientConfig.region;
table.connection.tableName;
So you can use the AWS SDK DynamoDB client like this:
new DynamoDB(table.connection.clientConfig);
License
This library is licensed under the MIT License.