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 batchGet(options: TableBatchGetOptions): BatchGetOutputNo description
inflight batchWrite(options: TableBatchWriteOptions): BatchWriteOutputNo description
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 batchGet(options: TableBatchGetOptions): BatchGetOutputNo description
inflight batchWrite(options: TableBatchWriteOptions): BatchWriteOutputNo description
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 batchGet(options: TableBatchGetOptions): BatchGetOutputNo description
inflight batchWrite(options: TableBatchWriteOptions): BatchWriteOutputNo description
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 batchGet(options: BatchGetOptions): BatchGetOutputNo description
inflight batchWrite(options: BatchWriteOptions): BatchWriteOutputNo description
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 batchGet(options: BatchGetOptions): BatchGetOutputNo description
inflight batchWrite(options: BatchWriteOptions): BatchWriteOutputNo description
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

IDynamoResource (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 batchGet(options: TableBatchGetOptions): BatchGetOutputNo description
inflight batchWrite(options: TableBatchWriteOptions): BatchWriteOutputNo description
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

BatchGetOptions (struct)

Input to the batchGet operation on a Client.

Properties

NameTypeDescription
RequestItems
Map
No description
ReturnConsumedCapacitystr?No description

BatchGetOutput (struct)

No description

Properties

NameTypeDescription
ConsumedCapacity
Array?
No description
Responses
Map<Array>?
No description
UnprocessedKeys
Map
No description

BatchWriteOptions (struct)

Input to the batchWrite operation on a Client.

Properties

NameTypeDescription
RequestItems
Map
No description
ReturnConsumedCapacitystr?No description
ReturnItemCollectionMetricsstr?No description

BatchWriteOutput (struct)

No description

Properties

NameTypeDescription
ConsumedCapacity
Array?
No description
ItemCollectionMetricsJson?No description
UnprocessedItems
Map?
No 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

DeleteRequest (struct)

Represents a request to perform a DeleteItem operation on an item.

Properties

NameTypeDescription
KeyJsonKey is a map of attribute name to attribute values, representing the primary key of the item to delete. All of the table's primary key attributes must be specified

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

PutRequest (struct)

Represents a request to perform a PutItem operation on an item.

Properties

NameTypeDescription
ItemJsonA map of attribute name to attribute values, representing the primary key of an item to be processed by PutItem. All of the table's primary key attributes must be specified, and their data types must match those of the table's key schema. If any attributes are present in the item that are part of an index key schema for the table, their types must match the index key schema.

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

TableBatchGetOptions (struct)

TableBatchGetOptions is used as an input to the batchGet operation on a Table or Client (through BatchGetOptions).

Properties

NameTypeDescription
AttributesToGet
Array?
No description
ConsistentReadbool?No description
ExpressionAttributeNames
Map?
No description
Keys
Array
No description
ProjectionExpressionstr?No description
ReturnConsumedCapacitystr?When passed in on a Table resource, ReturnConsumedCapacity will be hoisted to the top level inside of the request. When passed in on a Client resource (via BatchGetOptions), setting ReturnConsumedCapacity here has no effect, set it inside of the top-level instead.

TableBatchWriteOptions (struct)

TableBatchWriteOptions is used as an input to the batchWrite operation on a Table or Client (through BatchWriteOptions).

Properties

NameTypeDescription
DeleteRequests
Array?
DeleteRequests contains a list of DeleteItem operations to perform on this table.
PutRequests
Array?
PutRequests contains a list of PutItem operations to perform on this table.
ReturnConsumedCapacitystr?When passed in on a Table resource, ReturnConsumedCapacity will be hoisted to the top level inside of the request. When passed in on a Client resource (via BatchWriteOptions), setting ReturnConsumedCapacity here has no effect, set it inside of the top-level instead.
ReturnItemCollectionMetricsstr?When passed in on a Table resource, ReturnItemCollectionMetrics will be hoisted to the top level inside of the request. When passed in on a Client resource (via BatchWriteOptions), setting ReturnConsumedCapacity here has no effect, set it inside of the top-level instead.

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