New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@brightcove/dynamodb-connector

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brightcove/dynamodb-connector

Provides a set of helpful functions for connecting to DynamoDB and performing operations

  • 3.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
137
increased by1270%
Maintainers
0
Weekly downloads
 
Created
Source

DynamoDB Connector

package-info NPM NodeJS

Provides a standardized way to connect to an AWS DynamoDB database using the v3 AWS javascript SDK.

Install

npm install @brightcove/dynamodb-connector --save

Usage

Version 2.x

const { DynamoDBConnector } = require('@brightcove/dynamodb-connector');

// Localstack configuration example
const db = new DynamoDBConnector({
    clientConfig: {
        endpoint: 'http://localhost:4566,
        region: 'us-east-1'
    }
});
...
const result = await db.query({
    TableName: 'my-table',
    ...
});
Options
ParamTypeDescriptionRequired
clientConfigDynamoDBClientConfighttps://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-dynamodb/TypeAlias/DynamoDBClientConfigTypeyes
translateConfigTranslateConfighttps://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-dynamodb/TypeAlias/TranslateConfigno
loggerLoggerWhat will be used for logging errors (ie. logger.error()). console is used by default if not specifiedno

Version 3.x

This version includes breaking changes by requiring the DynamoDBDocument to be passed in as an option. This drasticaly reduces the size of this package and removes all external dependencies.

import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBConnector } from '@brightcove/dynamodb-connector';

const client = new DynamoDBClient({
    endpoint: 'http://localhost:4566',
    region: 'us-east-1'
});
const document = DynamoDBDocument.from(client);

const db = new DynamoDBConnector({ document });
...
const result = await db.query({
    TableName: 'my-table',
    ...
});
Options
ParamTypeDescriptionRequired
documentDynamoDBDocumenthttps://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-dynamodb/Class/DynamoDBDocumentyes
loggerLoggerWhat will be used for logging errors (ie. logger.error()). console is used by default if not specifiedno
Functions
Query
const result = await db.query({
  TableName: "CoffeeCrop",
  KeyConditionExpression: "#primaryKey = :originCountry AND #sortKey > :roastDate",
  ExpressionAttributeNames: {
    "#primaryKey": "OriginCountry",
    "#sortKey": "RoastDate",
  },
  ExpressionAttributeValues: {
    ":originCountry": "Ethiopia",
    ":roastDate": "2023-05-01",
  },
});

console.log(result.Items); // And array of items that match the query
Get
const result = await db.get({
  TableName: "AngryAnimals",
  Key: {
    CommonName: "Shoebill",
  }
});

console.log(result.Item); // The requested item
Put
const result = await db.put({
  TableName: "HappyAnimals",
  Item: {
    CommonName: "Shiba Inu",
  },
});
Update
const result = await db.update({
  TableName: "Dogs",
  Key: {
    Breed: "Labrador",
  },
  UpdateExpression: "set Color = :color",
  ExpressionAttributeValues: {
    ":color": "black",
  },
  ReturnValues: "ALL_NEW",
});

console.log(result.Attributes); // The updated item
ToUpdateExpression
const UpdateExpression = db.toUpdateExpression({
  SET: [
    { key: "Color", value: ":color" }
  ]
});

const result = await db.update({
  TableName: "Dogs",
  Key: {
    Breed: "Labrador",
  },
  UpdateExpression,
  ExpressionAttributeValues: {
    ":color": "black",
  },
  ReturnValues: "ALL_NEW",
});

console.log(result.Attributes); // The updated item
Delete
await db.delete({
  TableName: "Sodas",
  Key: {
    Flavor: "Cola",
  },
});
BatchGet
const keys = [{ Flavor: "Cola" }, { Flavor: "Sprite" }];

const result = await db.batchGet("Sodas", keys);

console.log(result.Items); // An array of the requested items
BatchWrite
const puts = [{ Flavor: "Cola" }, { Flavor: "Sprite" }]
  .map(db.toPutRequest);

const deletes = [{ Flavor: "Mountain Dew" }, { Flavor: "Dr. Pepper" }]
  .map((item) => db.toDeleteRequest(item, "Flavor"));

await db.batchWrite("Sodas", [ ...puts, ...deletes ]);
UUID
const uuid = db.uuid();

console.log(uuid); // A random UUIDv4

FAQs

Package last updated on 04 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc