npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@workgrid/dynamo-query-builder

v1.1.9

Published

An abstraction layer for the AWS SDK DynamoDB to construct query parameters for various operations. Supports both DynamoDB and DocumentClient type clients.

Downloads

134

Readme

DynamoDB Query Builder

An abstraction layer for the AWS SDK DynamoDB to construct query parameters for various operations. Supports both DynamoDB and DocumentClient type clients.

Examples

See a list of examples here.

Supported Dynamo operations

| Operation | Supported? | |-|:-:| | Get | ✓ | | Query | ✓ | | Delete | ✓ | | Scan | ✓ | | Update | ✓ | | Put | ✓ | | Batch Get | x | | Batch Write | x | | Create Set | x | | Transact Get | x | | Transact Write | x |

Supported Dynamo attributes

| Attributes | Supported? | |-|:-:| | Key | ✓ | | ExpressionAttributeNames | ✓ | | ExpressionAttributeValues | ✓ | | FilterExpression | ✓ | | IndexName | ✓ | | KeyConditionExpression | ✓ | | Limit | ✓ | | Item | ✓ | | ProjectionExpression | ✓ | | UpdateExpression | ✓ | | ConditionExpression | ✓ | | ExclusiveStartKey | ✓ | | ReturnConsumedCapacity | x | | ReturnItemCollectionMetrics | x | | ReturnValues | x | | ConsistentRead | x | | KeyConditions | x | | ScanIndexForward | x | | Select | x | | Segment | x | | TotalSegments | x | | ~~ConditionalOperator~~ - Legacy | ~ | | ~~AttributeUpdates~~ - Legacy | ~ | | ~~QueryFilter~~ - Legacy | ~ | | ~~ScanFilter~~ - Legacy | ~ | | ~~AttributesToGet~~ - Legacy | ~ | | ~~Expected~~ - Legacy | ~ |

Adding additional functionality

How to add addition operations?

An operation would be considered one of the functions that Dynamo provides, such as Get, Query, Put, Scan, etc

Examples of existing operations can be found in the operations directory.

Each of these operations are a single class being built up using a selection of attributes to make up it's functionality.

For example, the Get operation pulls in the following attributes;

  • Key
  • ProjectionExpression
  • ExpressionAttributeNames

This class exposes the set attribute functions using public access type, while keeping the get ones private by keeping them outside of the class entirely.

The get attributes are kept private, as they are only exposed and returned all together via the getConstructedQuery function.

Since the private and public keywords are only honoured in Typescript prior to compilation; when using in a Javascript project, private methods and attributes are visibly and accessable. In order to hide clutter, internal tags are used as a workaround for each private attribute.

Typically (But up to you), attribute set functions are chainable. Chainable function can be setup using the chainable utility, so that any attribute can be converted to this style, where it sees fit.

Each attribute's get function has been setup to return a spreadable object containing it's attribute(s), so the getConstructedQuery function can safely spread each attribute.

Once the operation class has been built, export the class in the main index file.


How to add additional attributes?

An attribute is one of the data objects that are expected to be present in the parameters object of an operation.

A list of all DocumentClient operation attributes can be found on the AWS documentation.

Each attribute can be constructed in any way you see fit, although, keep in consideration the design principles of the existing attributes in order to ensure consistency of expected behaviour;

  • Modular - Keep each attribute simple and only have functionality that it concerns
  • Isolated - An attribute should be responsible for changing, storing and returning it's own data properties
  • Build property only when accessed - Keep attribute data generic at "rest" and build into Dynamo/Document specific formats only when accessed via get.

Examples of existing attributes can be found in the attributes directory.

Typically, attributes consist of a Add/Set function and a Get function. Although, these can be named anything!

The attribute will modify it's property via the Add/Set function, and keep it in a generic state, where it will then be constructed into either DynamoDb or DocumentClient format when accessed via Get.

Shareable attributes

Sometimes, an attribute needs to modify the contents of another attribute.

For example, KeyConditionExpression needs to add to ExpressionAttributeValues.

In this case, make sure that the KeyConditionExpression only accesses and sets the ExpressionAttributeValues property through a parameter, and never returns another attribute's property, otherwise we introduce unmaintainable code!

See KeyConditionExpression for an example of this parameter passing.