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

slick-dynamodb

v2.0.0

Published

[![Node.js CI](https://github.com/evanandrewrose/slick-dynamodb/actions/workflows/node.js.yml/badge.svg)](https://github.com/evanandrewrose/slick-dynamodb/actions/workflows/node.js.yml)

Downloads

2

Readme

Slick DynamoDB

Node.js CI

This is a small wrapper around the DynamoDB Document Client, which removes the burden of managing attribute names and values by introducing helper methods that are used in conjunction with the SlickDynamoDB wrapper.

See the comparison below:

{ // dynamodb document api
  UpdateExpression: 'set path.to.#identifier = :new_count',
  ExpressionAttributeNames: {
      '#identifier': 'count'
  },
  ExpressionAttributeValues: {
      ':new_count': 1
  }
}

// is equivalent to:

{ // slick api
  UpdateExpression: ["set path.to.", n('count'), " = ", v(1)],
}

Installation

npm i --save slick-dynamodb

Example Usage

To use, just import the APIs as shown below and then write your expressions as a list of strings/attributes by wrapping the attribute names with n() and values with v().

import { SlickDynamoDB, name as n, value as v } from "slick-dynamodb";

const user = "evan";
const client = new SlickDynamoDB(documentClient);

await client
  .update({
    TableName: "MyTable",
    Key: {
      pk: "GAME#001",
      sk: "GAME#001",
    },
    UpdateExpression: [
      ["SET users.", n(user), ".ready = ", v(true)],
      ["ADD version ", v(1)],
    ],
    ConditionExpression: [
      ["attribute_exists(users.", n(user), ")"],
      [n("state"), " = ", v("WAITING")],
      ["version = ", v(1)],
    ],
    ReturnValues: "ALL_NEW",
  })
  .promise();

This is equivalent to:

await documentClient
  .update({
      {
        TableName: "MyTable",
        Key: {
          pk: "GAME#001",
          sk: "GAME#001",
        },
        UpdateExpression:
          "SET users.#user.ready = :ready " +
          "ADD version :increment",
        ConditionExpression:
          "(attribute_exists(users.#user)) " +
          "AND (#state = :state) " +
          "AND (version = :version)",
        ExpressionAttributeNames: {
          "#user": "evan",
          "#state": "state",
        },
        ExpressionAttributeValues: {
          ":ready": true,
          ":state": "WAITING",
          ":increment": 1,
          ":version": 1,
        },
        ReturnValues: "ALL_NEW",
  })
  .promise();

Working with the client APIs

All of the DynamoDB Document APIs are supported. If the Document API allowed you to reference a given input property, then SlickDynamoDB expects a SlickExpression.

A SlickExpression can be:

  • A unary expression:
    • single attribute: v(123)
    • string: "attribute_exists(foo)"
  • A composite expression:
    • attributes and strings: ['name = ', n('evan')]
    • only attributes: [n('foo'), n('bar')]
  • A list of composite expressions:
    • list of above expressions: [["foo = ", n(foo)], ["bar = ", v(bar)]]

Passing a list of composite expressions

The rules for what happens when you pass a composite expression (2d array) depends on the type of expressions you're working with, but they're generally what you would want if you we're sending multiple expressions of the same type. See the below table for details:

| Type | Description | | ----------------------------------------------------------------- | -------------------------------------------------------------------- | | UpdateExpression | Expressions are joined by a space character. | | ConditionExpression, KeyConditionExpression, and FilterExpression | Expressions are joined by "AND". Each expression is wrapped with (). | | ProjectionExpression | Won't pass type check. |

Projection Expressions

Because projections are csv-lists, the API will only accept single-dimensional expressions. Below are examples:

ProjectionExpression: "foo"; // valid
ProjectionExpression: n("foo"); // valid
ProjectionExpression: [n("foo"), n("bar")]; // valid
ProjectionExpression: [
  [n("foo"), n("bar")],
  [n("foo"), n("bar")],
]; // invalid, won't compile

This work is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Amazon, or any of its subsidiaries or its affiliates.