2.1.2 • Published 1 year ago

@nuskin/dynamodb-utils v2.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@nuskin/dynamodb-utils

This module is a wrapper for DynamoDB calls for getting/writting/deleting records from a DynamoDB table.

Installing

Usng npm:

npm add @nuskin/dynamodb-utils

Usng yarn:

yarn add @nuskin/dynamodb-utils

Example usage

const {
    batchGet,
    batchWrite,
    get,
    query,
    scan,
    put,
    update,
    transactWrite,
    remove
} = require('@nuskin/dynamodb-utils');

// batchGet
const tablename = 'your_table';
const keys = [{pKey: 'pkey1', skey: 'skey1'}, {pKey: 'pkey2', skey: 'skey2'}];
const records = await batchGet(keys, tableName);

// batchWrite
const records = [
    {pKey: 'pkeyValue', skey: 'skeyValue', field: 'fieldValue'},
    {pKey: 'pkeyValue', skey: 'skeyValue', field: 'fieldValue'}
];
await batchWrite(keys, tableName);

// get
const record = await get({Key: {pKey: 'pKeyValue', sKey: 'sKeyValue'}}, tableName);

// query - calls DynamoDBClient.query once passing back its response
const queryResponse = await query({
        KeyConditionExpression: 'pKey = :pKey',
        ExpressionAttributeValues: {':pKey': 'keyValue'},
        Limit: 50
    }, tableName);

// query - calls DynamoDBClient.query calling multiple times if necessary to get a complete response
const queryRecords = await queryAll({
        KeyConditionExpression: 'pKey = :pKey',
        ExpressionAttributeValues: {':pKey': 'keyValue'},
        Limit: 50
    }, tableName);

// scan - only calls DynamoDBClient once passing back its response
const scanRespons = await scan({ // leave empty if no filtering required
        FilterExpression: 'field = :fieldValue',
        ExpressionAttributeValues: {
            ":fieldValue": "test"
          }
    }, tableName);

// scan - calls DynamoDBClient.scan until the whole table has been scanned.
const scanRecords = await scanTable({ // leave empty if no filtering required
        FilterExpression: 'field = :fieldValue',
        ExpressionAttributeValues: {
            ":fieldValue": "test"
          }
    }, tableName);

// put - puts the given Item to the dynamoDB table
const putResponse = await put({
    Item: {
        pKey: 'pKeyValue', sKey: 'sKeyValue'}
    }, tableName);

// update
const updateResponse = await update(params, tableName);

// transactWrite
const transactWriteResponse = await transactWrite(params, tableName);

// remove
const removeResponse = await remove({Key: {
            pKey: 'pKeyValue', sKey: 'sKeyValue'
        }}, tableName);

Resources

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/

License

MIT

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago