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

dynamodb-utility

v1.3.5

Published

Simple DynamoDB Utility

Downloads

27

Readme

Build Status License


Table of Contents


Features

Basic DynamoDB operation in table

  • get
  • put
  • update
  • patch
  • delete
  • scan
  • query
  • raw

support dynamodb Comparison Operator and Function

support nested attribute filter expression

Installation

$ npm install --save dynamodb-utility

Setup

  • ตั้งค่า AWS IAM

    • ตั้งค่า User และให้ policy ให้เรียบร้อย และนำใน AWS Access Key ID และ AWS Secret Access Key มาใช้
  • ตั้งค่า AWS Environment

    • แนะนำให้ติดตั้ง AWS CLI และ Configuration Environment พื้นฐานให้เรียบร้อย อ่านเพิ่มเติมเกี่ยวกับ AWS Configure
  • ตรวจสอบ AWS Environment

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

Example Code

สามารถดูตัวอย่างการเขียนได้ที่

example code


Usage

โดยพื้นฐานแล้ว Library จะใช้ AWS Environment ที่อยู่บนเครื่องในการตั้งค่า AWS DynamoDB ใน Module

import DynamodbUtil from 'dynamodb-utility'
const userModel = new DynmodbUtil('User-Table', {
    region: 'ap-southeast-1',
    // ...DynamoDBUtilOptions
});

Put

userModel.put({
    pkey: 'User1',
    skey: 'Profile',
    firstname: 'Araiva',
    lastname: 'Viruskizz',
    gender: 'Male',
    age: 20,
    address: {
        province: 'London',
        country: 'England'
    }
}).then(res => console.log(res));

Get

userModel.get({ pkey: 'User1', skey: 'Profile'})
    .then(res => console.log(res));

Update

userModel.update({ id: 'User1', skey: 'Profile'}, {
    age: 20
}).then(res => console.log(res));

Patch

userModel.patch({ id: 'User1', skey: 'Profile'}, {
    age: 20,
    'address.province': 'Man Chester'
}).then(res => console.log(res));

Delete

userModel.delete({ pkey: 'User1', skey: 'Profile' })
    .then(res => console.log(res));

Scan

userModel.scan().then(res => console.log(res));

// or by pass argument scan option
// DynamodbUtil.query(ScanOptions);
userModel.scan({
    filter: {
        gender: 'Male',
        age: {
            greaterThan: 10
        },
        'address.country': 'England'
    },
    attributes: ['firstname', 'lastname', 'age']
}).then(res => console.log(res));

Query

// DynamodbUtil.query(QueryOptions);
userModel.query({
    keyCondition: {
        pkey: 'User1',
        skey: {
            beginsWith: 'Profile'
        }
    }
}).then(res => console.log(res));

Raw (Use Raw DynamodbClient)

// DynamodbUtil.raw.scan(ScanParam);
userModel.raw.scan({
    Table: 'User-Table'
}).promise().then(res => console.log(res.Items));

Attribute Reference

DynamoDBUtilOptions

| Variable | Type | Required | Default | | --------------- |:-------------:| ---------:| --------:| | region | string | false | env: AWS_REGION | | timestamp | boolean | false | NO| | accessKeyIds | string | false | env: AWS_ACCESS_KEY| | secretAccessKey | string | false | env: AWS_SECRET_KEY|

ScanOptions

| Variable | Type | Required | Description | | --------------- |:---------------:| ---------:| --------:| | filter | KeyCondition | true | เงื่อนไขการกรอง ดู KeyCondition เพิ่มเติม| | limit | string | false | จำกัดจำนวนผลลัพธ์ | | lastKey | boolean | false | Key สุดท้ายเพื่อทำ Pagination | | times | string | false | จำนวนรอบของการแสกน | | indexName | string | false | ชื่อ index กรณีใช้ GSI หรือ LSI| | attributes | Array | false | Attribute ที่ต้องการเลือกออกมาแสดง|

QueryOptions (extended from ScanOptions)

| Variable | Type | Required | Description | | --------------- |:---------------:| ---------:| --------:| | keyCondition | KeyCondition | false | เงื่อนไขการ Query ดู KeyCondition เพิ่มเติม| | filter | KeyCondition | false | เงื่อนไขการกรอง ดู KeyCondition เพิ่มเติม| | sort | 'DESC' or 'ASC' | false | เรียงลำดับตาม sort key ,default: ASC

KeyCondition

Attribute: 'Value'
  
Or 
  
Attribute: {
    ConditionFunction: 'Value'
}

ConditionFunction ที่สามารถเรียกใช้งานได้

  • equal
  • greaterThan
  • lessThan
  • attributeExists
  • attributeNotExists
  • beginsWith
  • contains

ดูรายละเอียดเพิ่มเติ่ม Comparison Operator and Function Reference

Contributors

Or Contributors/People

| Araiva Viruskizz | | :---: | viruskizz


Support

Reach out to me at one of the following places!

  • Website at developer.fbw.center
  • Facebook at ceremonial.statistic.center

License

License