项目作者: kdcio

项目描述 :
Lightweight DynamoDB ODM
高级语言: JavaScript
项目地址: git://github.com/kdcio/ddb.git
创建时间: 2020-08-23T14:52:59Z
项目社区:https://github.com/kdcio/ddb

开源协议:MIT License

下载


KDC DDB

A lightweight object modeling for DynamoDB inspired by Mongoose.

The default database operations of this package assumes single table design but all can be overridden by writing your own.

@kdcio/ddb"">ver @kdcio/ddb"">size build Known Vulnerabilities Quality Gate Status Code Smells Coverage license

Installation

  1. npm i @kdcio/ddb

Quick Start

  1. Define database table name in environment variable.

    In code:

    1. process.env.DDB_TABLE = 'my-dynamodb-table';

    or in serverless.yml:

    1. provider:
    2. environment:
    3. DDB_TABLE: 'my-dynamodb-table'

    or in package.json:

    1. "scripts": {
    2. "start": "DDB_TABLE='my-dynamodb-table' node index.js"
    3. }

    Note that table creation needs to be done outside this package to allow flexibility.

  2. Define the fields of the document.

    1. const fields = {
    2. id: { required: true },
    3. name: { required: true },
    4. type: { required: true },
    5. };
  3. Define primary and secondary keys

    1. const pKey = { pk: '{type}#{id}', sk: 'ANIMAL#{type}' };
    2. const sKey = { pk2: 'ANIMAL', sk2: '{type}#{id}' };
  4. Create schema

    1. const schema = new DDB.Schema(fields, pKey, sKey);
  5. Create class

    1. const Animal = DDB.model('Animal', schema);
  6. Create an instance document from data object

    1. const dog = new Animal({ id: 1, name: 'sparkle', type: 'dog' });
    2. await dog.save();
  7. Check the tests folder for more examples.

Debugging

This package uses debug.

To enable:

  1. DEBUG=ddb:* node app.js

Sonar Cloud Badges

Quality Gate Status Coverage Code Smells Bugs Lines of Code Duplicated Lines (%) Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities