eudynamys
v1.0.4
Published
A simple query builder for DynamoDB
Readme
eudynamys
Yet another simple query builder for DynamoDB. Give it a try!
Install
npm install --save eudynamyseudynamys requires Node 6+.
Usage
Instantiate the client
const AWS = require('aws-sdk');
const dbDocClient = new AWS.DynamoDB.DocumentClient();
const QueryBuilder = require('eudynamys');
const qb = new QueryBuilder(dbDocClient);Debug
You can pass a debug function as 2nd parameter of QueryBuilder constructor. It will displays the parameters passed to DynamoDB document client. Use either console.log or a custom logger.
const qb = new QueryBuilder(dbDocClient, console.log);API
Filters and methods return this
table(tableName),from(tableName)Select a tableindex(indexName)Select an indexitem(object = {})Define an item to putselect(attributeName = '')Attributes to fetchexclusiveStartKey(key)In order to loopscanIndexForward(value)To define the order for traversal indexlimit(number)Maximum number of itemscount()Countwhere(keyAttributeName = '')Wherefilter(attributeName = '')Filterif(attributeName = '')Ifmatch(joiSchema = {})Match a Joi schemaequals(...args),eq(...args)Equalsne(...args)Not equalslte(...args)Lower than or equallt(...args)Lower thangte(...args)Greater than or equalgt(...args)Greater thanbetween(...args)Betweenin(...args)Inand(...args)Andor(...args)Ornot(...args)Notop(...args)Open parenthesiscp(...args)Close parenthesis
Actions, return a Promise resolved with DynamoDB response.
put()update()query()scan()get()
Example
qb.select(['uuid', 'title', 'createdAt'])
.from('sample')
.where('key').eq('8e7d307b-4e1b-4f26-984b-dfc2b35bdbbc')
.filter('published').eq(false)
.and().begins('type', 'Ty')
.and('createdAt').gt(1457278812)
.query();Lint
npm run lintTest
Requires node 8+. Will install a DynamoDB local server using dynamodb-localhost, create and seed a table, and validate results.
npm run test
