Skip to content

Repository files navigation

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.

versizebuildKnown VulnerabilitiesQuality Gate StatusCode SmellsCoveragelicense

Installation

npm i @kdcio/ddb

Quick Start

  1. Define database table name in environment variable.

    In code:

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

    or in serverless.yml:

    provider:
    environment:
    DDB_TABLE: 'my-dynamodb-table'

    or in package.json:

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

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

  2. Define the fields of the document.

    constfields={id: {required: true},name: {required: true},type: {required: true},};
  3. Define primary and secondary keys

    constpKey={pk: '{type}#{id}',sk: 'ANIMAL#{type}'};constsKey={pk2: 'ANIMAL',sk2: '{type}#{id}'};
  4. Create schema

    constschema=newDDB.Schema(fields,pKey,sKey);
  5. Create class

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

    constdog=newAnimal({id: 1,name: 'sparkle',type: 'dog'});awaitdog.save();
  7. Check the tests folder for more examples.

Debugging

This package uses debug.

To enable:

DEBUG=ddb:* node app.js

Sonar Cloud Badges

Quality Gate StatusCoverageCode SmellsBugsLines of CodeDuplicated Lines (%)Maintainability RatingReliability RatingSecurity RatingTechnical DebtVulnerabilities

About

Lightweight DynamoDB ODM

Topics

Resources

Code of conduct

Stars

1 star

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages