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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dynamo-crud

v2.2.8

Published

A wrapper lib for the official SDK provides an easier to use CRUD API and type safety.

Downloads

78

Readme

Dynamo-CRUD

A wrapper lib for the official SDK which provide an easier to use CRUD API and type safety.

Main Features

  • Easier to understand fluid APIs
  • Auto marshall/unmarshall the DTO object
  • Use Stream API for scan and query command
  • Transparently use Batch GetItem/WriteItem
  • Advanced type hinting for TypeScript users
  • Adjust requests size automatically on BatchWriteItem

Installation

npm i dynamo-crud

Basic Usage

import { DynamoTable } from "dynamo-crud"
import { DynamoDB } from "@aws-sdk/client-dynamodb"

const dynamoTable = new DynamoTable({
  client: new DynamoDB({ region: process.env.REGION }),
  tableName: "posts",
  partitionKey: "id",
  sortKey: "title",
})

async function run() {
  /*
  |---------------------------------------------------------------------------
  | scan items
  |---------------------------------------------------------------------------
  */
  const readableStreamScan = dynamoTable.scan().createReadableStream()

  for await (const { data, rawResponse } of readableStreamScan) {
    console.log(data, rawResponse)
  }

  /*
  |---------------------------------------------------------------------------
  | query items
  |---------------------------------------------------------------------------
  */
  const readableStreamQuery = dynamoTable
  .query({ id: 100 })
  .index("byTitle")
  .where("title", "=", "myTitle")
  .createReadableStream()

  for await (const { data, rawResponse } of readableStreamQuery) {
    console.log(data, rawResponse)
  }

  /*
  |---------------------------------------------------------------------------
  | Get a single item (GetItem)
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .find({ id: 100, title: "hello" })
  .run()

  /*
  |---------------------------------------------------------------------------
  | Get mutiple items (BatchGetItem)
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .find([ { id: 100, title: "hello" }, { id: 99, title: "hi" } ])
  .run()

  /*
  |---------------------------------------------------------------------------
  | Delete a single item
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .delete({ id: 100, title: "hello" })
  .run()

  /*
  |---------------------------------------------------------------------------
  | Delete mutiple items (BatchWriteItem)
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .delete([ { id: 100, title: "hello" }, { id: 99, title: "hi" } ])
  .run()

  /*
  |---------------------------------------------------------------------------
  | Put a single item (PutItem)
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .put({ id: 100, title: "hello" })
  .run()

  /*
  |---------------------------------------------------------------------------
  | Put mutiple items (BatchWriteItem)
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .put([ { id: 100, title: "hello" }, { id: 99, title: "hi" } ])
  .run()

  /*
  |---------------------------------------------------------------------------
  | update a single item
  |---------------------------------------------------------------------------
  */
  let { data, rawResponse } = await dynamoTable
  .update({ id: 100, title: "hello" })
  .set("title", "hello world")
  .add("likeCount", 1)
  .delete("categories", new Set(["cat-1"]))
  .run()

  
  /*
  |---------------------------------------------------------------------------
  | query then update the quired items
  |---------------------------------------------------------------------------
  */
  await dynamoTable
  .query({ id: 100 })
  .index("byLikeCount")
  .where("likeCount", ">", 100)
  .update.set("author.id", 100)
  .run() // or call `.createReadableStream()` if you are going to use the returned raw response.
}

run()

Utils

  • consume
  • getOneItem

Examples:

const scanCommand = dynamoTable.scan()
const queryCommand = dynamoTable.query({ id: 100 }).index('byID')

async function run() {
  const item = await getOneItem()

  await consume((item) => {
    console.log(item)
  }, scanCommand)
}

run()

TypeScript

To obtain the type hinting, give the type of the table structure, the partition key, the sort key.

For example:

export type PostModel = {
  id: number
  title: string
  tags: string[]
  categories: Set<string>
  likeCount: number
  author: {
    id: number
    name: string
    followers: {
      name: string
    }[]
  }
  comments: {
    text: string
    likeCount: number
  }[]
}

// PK: 'id'  SK: 'title'
const dynamoTable = new DynamoTable<PostModel, 'id', 'title'>({
  client: mockDynamoDB,
  tableName: 'posts',
  partitionKey: "id",
  sortKey: "title",
})


dynamoTable.query({id: '100'})
// error: `id` should be number


dynamoTable
  .update({id: 100}) // [error] `title` is required
  .set('author.name_x', 'foo') // [error] `author.name_x` is not the correct path
  .set('comments.0.likeCount', '1000') // [error] `likeCount` should be `number`
  .add('tags', 1000) // [error] `tags` is not allowed to perferm `add` operation
  .delete('tags', 'tag-1') // [error] `tags` is not allowed to perferm `delete` operation