Skip to main content

Amazon 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.

API Reference

Table of Contents

Table (preflight class)

No description

Constructor

new(props: TableProps): Table

Properties

NameTypeDescription
connectionConnectionNo description
tableNamestrNo description

Methods

SignatureDescription
inflight delete(options: DeleteOptions): DeleteOutputNo description
inflight get(options: GetOptions): GetOutputNo description
inflight put(options: PutOptions): PutOutputNo description
inflight query(options: QueryOptions): QueryOutputNo description
inflight readWriteConnection(): ConnectionNo description
inflight scan(options: ScanOptions?): ScanOutputNo description
setStreamConsumer(handler: inflight (StreamRecord): void, opts: StreamConsumerOptions?): voidNo description
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutputNo description
inflight update(options: UpdateOptions): UpdateOutputNo description

Table_tfaws (preflight class)

No description

Constructor

new(props: TableProps): Table_tfaws

Properties

NameTypeDescription
connectionConnectionNo description
tableNamestrNo description

Methods

SignatureDescription
inflight delete(options: DeleteOptions): DeleteOutputNo description
inflight get(options: GetOptions): GetOutputNo description
inflight put(options: PutOptions): PutOutputNo description
inflight query(options: QueryOptions): QueryOutputNo description
inflight readWriteConnection(): ConnectionNo description
inflight scan(options: ScanOptions?): ScanOutputNo description
setStreamConsumer(handler: inflight (StreamRecord): void, options: StreamConsumerOptions?): voidNo description
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutputNo description
inflight update(options: UpdateOptions): UpdateOutputNo description

Table_sim (preflight class)

No description

Constructor

new(props: TableProps): Table_sim

Properties

NameTypeDescription
connectionConnectionNo description
tableNamestrNo description

Methods

SignatureDescription
inflight delete(options: DeleteOptions): DeleteOutputNo description
inflight get(options: GetOptions): GetOutputNo description
inflight put(options: PutOptions): PutOutputNo description
inflight query(options: QueryOptions): QueryOutputNo description
inflight readWriteConnection(): ConnectionNo description
inflight scan(options: ScanOptions?): ScanOutputNo description
setStreamConsumer(handler: inflight (StreamRecord): void, options: StreamConsumerOptions?): voidNo description
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutputNo description
inflight update(options: UpdateOptions): UpdateOutputNo description

Client (inflight class)

No description

Constructor

new(): Client

Properties

No properties

Methods

SignatureDescription
inflight delete(options: DeleteOptions): DeleteOutputNo description
inflight get(options: GetOptions): GetOutputNo description
inflight put(options: PutOptions): PutOutputNo description
inflight query(options: QueryOptions): QueryOutputNo description
inflight scan(options: ScanOptions?): ScanOutputNo description
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutputNo description
inflight update(options: UpdateOptions): UpdateOutputNo description

IClient (interface)

No description

Properties

No properties

Methods

SignatureDescription
inflight delete(options: DeleteOptions): DeleteOutputNo description
inflight get(options: GetOptions): GetOutputNo description
inflight put(options: PutOptions): PutOutputNo description
inflight query(options: QueryOptions): QueryOutputNo description
inflight scan(options: ScanOptions?): ScanOutputNo description
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutputNo description
inflight update(options: UpdateOptions): UpdateOutputNo description

ITable (interface)

No description

Properties

No properties

Methods

SignatureDescription
inflight delete(options: DeleteOptions): DeleteOutputNo description
inflight get(options: GetOptions): GetOutputNo description
inflight put(options: PutOptions): PutOutputNo description
inflight query(options: QueryOptions): QueryOutputNo description
inflight readWriteConnection(): ConnectionNo description
inflight scan(options: ScanOptions?): ScanOutputNo description
setStreamConsumer(handler: inflight (StreamRecord): void, options: StreamConsumerOptions?): voidNo description
inflight transactWrite(options: TransactWriteOptions): TransactWriteOutputNo description
inflight update(options: UpdateOptions): UpdateOutputNo description

AttributeDefinition (struct)

No description

Properties

NameTypeDescription
namestrNo description
typestrNo description

ClientConfig (struct)

No description

Properties

NameTypeDescription
credentialsCredentialsNo description
endpointstrNo description
regionstrNo description

Connection (struct)

No description

Properties

NameTypeDescription
clientConfigClientConfig?No description
tableNamestrNo description

Credentials (struct)

No description

Properties

NameTypeDescription
accessKeyIdstrNo description
secretAccessKeystrNo description

DeleteOptions (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
KeyJsonNo description
ReturnValuesstr?No description

DeleteOutput (struct)

No description

Properties

NameTypeDescription
AttributesJson?No description

GetOptions (struct)

No description

Properties

NameTypeDescription
ConsistentReadbool?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
KeyJsonNo description
ProjectionExpressionstr?No description

GetOutput (struct)

No description

Properties

NameTypeDescription
ItemJson?No description

GlobalSecondaryIndex (struct)

No description

Properties

NameTypeDescription
hashKeystrNo description
namestrNo description
nonKeyAttributes
Array?
No description
projectionTypestrNo description
rangeKeystr?No description
readCapacitynum?No description
writeCapacitynum?No description

PutOptions (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
ItemJsonNo description
ReturnValuesstr?No description

PutOutput (struct)

No description

Properties

NameTypeDescription
AttributesJson?No description

QueryOptions (struct)

No description

Properties

NameTypeDescription
ConsistentReadbool?No description
ExclusiveStartKeyJson?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
FilterExpressionstr?No description
IndexNamestr?No description
KeyConditionExpressionstrNo description
Limitnum?No description
ProjectionExpressionstr?No description
ReturnConsumedCapacitystr?No description
ScanIndexForwardbool?No description
Selectstr?No description

QueryOutput (struct)

No description

Properties

NameTypeDescription
ConsumedCapacityJson?No description
CountnumNo description
Items
Array
No description
LastEvaluatedKeyJson?No description
ScannedCountnumNo description

ScanOptions (struct)

No description

Properties

NameTypeDescription
ConsistentReadbool?No description
ExclusiveStartKeyJson?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
FilterExpressionstr?No description
IndexNamestr?No description
Limitnum?No description
ProjectionExpressionstr?No description
ReturnConsumedCapacitystr?No description
Segmentnum?No description
Selectstr?No description
TotalSegmentsnum?No description

ScanOutput (struct)

No description

Properties

NameTypeDescription
ConsumedCapacityJson?No description
CountnumNo description
Items
Array
No description
LastEvaluatedKeyJson?No description
ScannedCountnumNo description

StreamConsumerOptions (struct)

No description

Properties

NameTypeDescription
batchSizenum?No description
startingPositionstr?No description

StreamRecord (struct)

No description

Properties

NameTypeDescription
dynamodbStreamRecordDynamodbNo description
eventIDstrNo description
eventNamestrNo description

StreamRecordDynamodb (struct)

No description

Properties

NameTypeDescription
ApproximateCreationDateTimestrNo description
KeysJsonNo description
NewImageJson?No description
OldImageJson?No description
SequenceNumberstrNo description
SizeBytesnumNo description
StreamViewTypestrNo description

TableProps (struct)

No description

Properties

NameTypeDescription
attributes
Array
No description
billingModeBillingMode?Billing mode for the table. Defaults to PAY_PER_REQUEST.
deletionProtectionbool?Enables deletion protection for table. Disabled by default. For the Terraform AWS provider, this will also enable lifecycle { prevent_destroy = true }
globalSecondaryIndex
Array?
No description
hashKeystrNo description
namestr?No description
pointInTimeRecoverybool?No description
rangeKeystr?No description
timeToLiveAttributestr?No description

TransactWriteItem (struct)

No description

Properties

NameTypeDescription
ConditionCheckTransactWriteItemConditionCheck?No description
DeleteTransactWriteItemDelete?No description
PutTransactWriteItemPut?No description
UpdateTransactWriteItemUpdate?No description

TransactWriteItemConditionCheck (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
KeyJsonNo description
ReturnValuesOnConditionCheckFailurebool?No description

TransactWriteItemDelete (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
KeyJsonNo description
ReturnValuesOnConditionCheckFailurebool?No description

TransactWriteItemPut (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
ItemJsonNo description
ReturnValuesOnConditionCheckFailurebool?No description

TransactWriteItemUpdate (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
KeyJsonNo description
ReturnValuesOnConditionCheckFailurebool?No description
UpdateExpressionstr?No description

TransactWriteOptions (struct)

No description

Properties

NameTypeDescription
TransactItems
Array
No description

TransactWriteOutput (struct)

No description

Properties

No properties

UpdateOptions (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
KeyJsonNo description
ReturnConsumedCapacitystr?No description
ReturnValuesstr?No description
UpdateExpressionstrNo description

UpdateOutput (struct)

No description

Properties

NameTypeDescription
ConditionExpressionstr?No description
ExpressionAttributeNames
Map?
No description
ExpressionAttributeValues
Map?
No description
ItemJsonNo description
ReturnValuesstr?No description

ClientProps (struct)

No description

Properties

NameTypeDescription
credentialsCredentials?No description
endpointstr?No description
regionstr?No description
tableNamestrNo description

BillingMode (enum)

No description

Values

NameDescription
PAY_PER_REQUESTNo description
PROVISIONEDNo description