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-processor

v3.0.3

Published

DynamoDB operation processor for Node.js

Downloads

142

Readme

dynamo-processor

NPM Version Node CI Coverage Status

DynamoDB processor operates a process by simple JSON expression.

Features

  • If it have failed to set child objects to Map Type field, auto trying to update with initial fields again. futhermore, If it have failed by the conflict, auto trying the updating process at first once more.
  • Node.js 12 or later
  • AWS SDK for JavaScript v3

Click here for the version that supports AWS SDK v2

Install

$ npm install -save @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb @aws-sdk/util-dynamodb
$ npm install -save dynamo-processor

How to Use

const DynamoProcessor = require('dynamo-processor')
const dp = new DynamoProcessor({ region: 'ap-northeast-1' });

new DynamoProcessor(options)

  • options <Object> DynamoDBClientConfig as well
    • wrapFunc <Boolean> If this is true, proc method returns a Function that wraps the Promise in case that promise evaluation need lazy. (default is false)

Methods

  • proc method is to analyze an item and to process the item by the action
  • get, put, update, delete, batchWrite, batchDelete methods as shortcut for each action

getItem

proc({ action: 'get', table, key })

dp.proc({
  table: 'users',
  action: 'get', // optional
  key: {
    id: 1
  }
})
.then((item) => {
  console.log(item); // { name: 'Taro', id: 1, age: 16 }
});

get(key)

dp.get('users', { id: 1 });

batchGetItem

proc({ action: 'get', table, keys })

dp.proc({
  table: 'users',
  action: 'get', // optional
  keys: [
    { id: 1 },
    { id: 2 }
  ]
})
.then((items) => {
  console.log(items[0]); // { id: 1, ... }
  console.log(items[1]); // { id: 2, ... }
});

putItem

dp.proc({
  table: 'users',
  action: 'put', // optional
  item: {
    id: 2,
    name: 'Michael',
    age: 25,
    address: {
      prefecture: 'Osaka'
    }
  }
})
.then((item) => {
  console.log(item);
  // { name: 'Michael',
  //   id: 2,
  //   address: { prefecture: 'Osaka' },
  //   age: 25 }
});

put(table, item)

dp.put('users', {
  id: 2,
  name: 'Michael',
  age: 25,
  address: {
    prefecture: 'Osaka'
  }
});

batchWriteItem (PutRequest)

proc({ action: 'put', table, items })

dp.proc({
  table: 'users',
  action: 'put', // optional
  items: [
    { id: 2, name: 'Michael' },
    { id: 3, name: 'Cindy' }
  ]
})
.then(unprocessedItems => {
  console.log(unprocessedItems); // undefined shows all success
});

batchWrite(table, items)

dp.batchWrite('users', [
  { id: 2, name: 'Michael' },
  { id: 3, name: 'Cindy' }
]);

updateItem

SET

The space in a key is instead of the separator (.) between parent and child because a space is rarely used for a variable name.

dp.proc({
  table: 'users',
  action: 'update', // optional
  key: {
    id: 3
  },
  set: {
    name: 'Taro',
    age: 14,
    'address prefecture': 'Tokyo'
  }
})
.then((item) => {
  console.log(item);
  // { name: 'Taro',
  //   id: 3,
  //   address: { prefecture: 'Tokyo' },
  //   age: 14 }
});

ADD

dp.proc({
  table: 'users',
  action: 'update', // optional
  key: {
    id: 3
  },
  add: {
    age: 1
  }
})
.then((item) => {
  console.log(item);
  // { name: 'Taro',
  //   id: 3,
  //   address: { prefecture: 'Tokyo' },
  //   age: 15 }  age was incremented
});

ADD to set

pushset is adding to NumberSet or StringSet or BinarySet.

dp.proc({
  table: 'users',
  action: 'update', // optional
  key: {
    id: 4
  },
  pushset: {
    cards: 30
  }
})
.then((item) => {
  console.log(item);
});

REMOVE

dp.proc({
  table: 'users',
  action: 'update', // optional
  key: {
    id: 3
  },
  remove: [
    'age',
    'address prefecture'
  ]
})
.then((item) => {
  console.log(item);
  // { name: 'Taro',
  //   id: 3,
  //   address: {} }  age and address.prefecture was removed
});

DELETE from set

delete is removing from NumberSet or StringSet or BinarySet.

dp.proc({
  table: 'users',
  action: 'update', // optional
  key: {
    id: 4
  },
  delete: {
    cards: 20
  }
})
.then((item) => {
  console.log(item);
});

update(table, keys, ope, [initFields])

dp.update('users', {
    id: 4
  },
  {
    set: { name: 'foo' }
  }
})
.then((item) => {
  console.log(item);
});

deleteItem

proc({ action: 'delete', table, key })

dp.proc({
  table: 'users',
  action: 'delete',
  key: {
    id: 1
  }
})
.then((item) => {
  console.log(item); // null
});

delete(table, keys)

dp.delete('users', { id: 1 });

batchWriteItem (DeleteRequest)

proc({ action: 'delete', table, keys })

dp.proc({
  table: 'users',
  action: 'delete',
  keys: [
    { id: 2 },
    { id: 3 }
  ]
})
.then(unprocessedItemKeys => {
  console.log(unprocessedItemKeys); // undefined shows all success
});

batchDelete(table, keys)

dp.batchDelete('users',[
  { id: 2 },
  { id: 3 }
])

Multiple items

getItems as Promise Array

Promise.all(
  dp.proc({
    table: 'users',
    action: 'get', // optional
    keys: [
      { id: 1 },
      { id: 2 }
    ]
  }, { useBatch: false })
)
.then((items) => {
  console.log(items[0]); // { id: 1, ... }
  console.log(items[1]); // { id: 2, ... }
});

putItems as Promise Array

Promise.all(
  dp.proc({
    table: 'users',
    action: 'put', // optional
    items: [
      { id: 1, val: 'foo' },
      { id: 2, val: 'bar' }
    ]
  }, { useBatch: false })
)
.then((items) => {
  console.log(items[0]); // { id: 1, ... }
  console.log(items[1]); // { id: 2, ... }
});

deleteItems as Promise Array

Promise.all(
  dp.proc({
    table: 'users',
    action: 'delete',
    keys: [
      { id: 1 },
      { id: 2 }
    ]
  }, { useBatch: false })
)
.then(results => {
  console.log(results[0]); // null
  console.log(results[1]); // null
});

createTable

dp.createTable('producthistories', {
    productId: 'S', // HASH key
    version: 'N'    // RANGE key
  },
  { // options
    readCU: 20, // default 5
    writeCU: 3   // default 5
  })
.then(() => {
  console.log('Succeeded to create table')
});

If first argument is object, it passes through as raw params. In short, dp.createTable(params) equals dynamodb.createTable(params).promise().

deleteTable

dp.deleteTable('producthistories')
.then(() => {
  console.log('Delete to create table')
});

LICENSE

MIT