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

dynamo-request-builder

v1.0.1

Published

An intuitive DynamoDB request building API

Downloads

75

Readme

Dynamo Request Builder

An intuitive DynamoDB request building API for JavaScript.

Contents

Installation

npm install dynamo-request-builder

Creating Requests

Use the DynamoRequestBuilderCreator with a DynamoDB DocumentClient to create a DynamoRequestBuilder.

import DynamoRequestBuilderCreator from "dynamo-request-builder";

const requestBuilder = new DynamoRequestBuilderCreator(dynamoDocClient).create("table_name");

Delete

import { attribute, sizeOf } from "dynamo-request-builder/attributes";
import { or } from "dynamo-request-builder/operators";
import { ReturnValues } from "dynamo-request-builder/return-values";

const request = requestBuilder.delete("partitionKeyName", "partitionKeyValue")
  .withSortKey("sortKeyName", "sortKeyValue") // Sort key condition
  .onlyIfAttribute("attribute").eq("value") // Add an attribute condition
  .onlyIfSizeOfAttribute("attribute").lte(1) // Add a size of attribute condition
  .onlyIf(
    or(attribute("attribute1").gte(1), attribute("attribute2").contains("value")),
    sizeOf("attribute3").eq(2)
  ) // Add multiple attribute conditions
  .returnValues(ReturnValues.AllOld); // Specify values to return

Get

const request = requestBuilder.get("partitionKeyName", "partitionKeyValue")
  .withSortKey("sortKeyName", "sortKeyValue") // Sort key condition
  .getAttributes("attribute", "attribute[0]", "attribute[0].subAttribute") // Specify attributes to retrieve
  .consistentRead(); // Use consistent read

Put

import { attribute, sizeOf } from "dynamo-request-builder/attributes";
import { not } from "dynamo-request-builder/operators";
import { ReturnValues } from "dynamo-request-builder/return-values";

const item = {
  ...
};

const request = requestBuilder.put(item)
  .ifItemNotExists("partitionKeyName", "sortKeyName") // Only put the item if it doesn't already exist
  .onlyIfAttribute("attribute").eq("value") // Add an attribute condition
  .onlyIfSizeOfAttribute("attribute").lte(1) // Add a size of attribute condition
  .onlyIf(
	  not(attribute("attribute1").gte(1)),
	  sizeOf("attribute3").eq(2)
  ) // Add multiple attribute conditions
  .returnValues(ReturnValues.AllOld); // Specify values to return

Query

import { attribute, sizeOf } from "dynamo-request-builder/attributes";
import { or } from "dynamo-request-builder/operators";

const request = requestBuilder.query("partitionKeyName", "partitionKeyValue")
  .whereSortKey("sortKeyName").beginsWith("value") // Add a sort key condition
  .whereAttribute("attribute").eq("value") // Add an attribute condition
  .whereSizeOfAttribute("attribute").lt(1) // Add a size of attribute condition
  .where(
    or(attribute("attribute1").gte(1), attribute("attribute2").contains("value")),
    sizeOf("attribute3").eq(2)
  ) // Add multiple attribute conditions
  .getAttributes("attribute", "attribute[0]", "attribute[0].subAttribute") // Specify attributes to retrieve
  .limit(5) // Specify a limit on the number of items to return
  .useIndex("indexName") // Specify an index to use
  .scanIndexDescending(); // Scan the index in descending order

Scan

import { attribute, sizeOf } from "dynamo-request-builder/attributes";
import { or } from "dynamo-request-builder/operators";

const request = requestBuilder.scan()
  .whereAttribute("attribute").eq("value") // Add an attribute condition
  .whereSizeOfAttribute("attribute").lt(1) // Add a size of attribute condition
  .where(
    or(attribute("attribute1").gte(1), attribute("attribute2").contains("value")),
    sizeOf("attribute3").eq(2)
  ) // Add multiple attribute conditions
  .getAttributes("attribute", "attribute[0]", "attribute[0].subAttribute") // Specify attributes to retrieve
  .limit(5) // Specify a limit on the number of items to return
  .useIndex("indexName") // Specify an index to use

Update

import { attribute, sizeOf, update } from "dynamo-request-builder/attributes";
import { or } from "dynamo-request-builder/operators";

const request = requestBuilder.update("partitionKeyName", "partitionKeyValue")
  .withSortKey("sortKeyName", "sortKeyValue") // Sort key condition
  .updateAttribute("attribute").incrementBy(5) // Add an update operation
  .operations(update("attribute1").add(1, 2, 3), update("attribute2").remove()) // Add multiple update operations
  .onlyIfAttribute("attribute").eq("value") // Add an attribute condition
  .onlyIfSizeOfAttribute("attribute").lte(1) // Add a size of attribute condition
  .onlyIf(
    or(attribute("attribute1").gte(1), attribute("attribute2").contains("value")),
    sizeOf("attribute3").eq(2)
  ) // Add multiple attribute conditions
  .returnValues(UpdateReturnValues.UpdatedNew); // Specify values to return

You can check the generated request parameters for yourself by accessing request.params.

Attributes

The ability to select specific attributes and apply constraint conditions and update operations to them are needed for certain expressions.

Logical Operators

Logical operators are used to extend the logic of condition expressions, filter expressions and key condition expressions.

Executing Requests

Once a request has been created, it can be executed and the return values can be used.