Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mhart/dynamo-table
A lightweight module to map JS objects and queries to DynamoDB tables
https://github.com/mhart/dynamo-table
Last synced: 14 days ago
JSON representation
A lightweight module to map JS objects and queries to DynamoDB tables
- Host: GitHub
- URL: https://github.com/mhart/dynamo-table
- Owner: mhart
- License: mit
- Created: 2013-04-21T02:37:44.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-22T21:39:36.000Z (over 10 years ago)
- Last Synced: 2024-10-12T23:40:15.152Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 575 KB
- Stars: 24
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
dynamo-table
------------[![Build Status](https://secure.travis-ci.org/mhart/dynamo-table.png?branch=master)](http://travis-ci.org/mhart/dynamo-table)
A lightweight module to map JS objects and queries to
[DynamoDB](http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API.html)
tables (supports the latest API version, 2012-08-10).This builds upon the [dynamo-client](https://github.com/jed/dynamo-client)
module, although any client that supports a simple `request` method will also
work.Example
-------```javascript
var dynamoTable = require('dynamo-table')// Will use us-east-1 and credentials from process.env unless otherwise specified
var table = dynamoTable('Orders', {key: ['customerId', 'orderId']})table.put({customerId: 23, orderId: 101, lineItemIds: [1, 2, 3]}, function(err) {
if (err) throw errtable.put({customerId: 23, orderId: 102, lineItemIds: [4, 5, 6]}, function(err) {
if (err) throw errtable.query({customerId: 23, orderId: {'>': 101}}, function(err, items) {
if (err) throw errconsole.log(items)
// [{customerId: 23, orderId: 102, lineItemIds: [4, 5, 6]}]
})
})
})
```API
---### dynamoTable(name, [options])
### new DynamoTable(name, [options])Constructor of the table, including DynamoDB details, keys, mappings, etc
### get(key, [options], callback)
Corresponds to [GetItem](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GetItem.html)
### put(jsObj, [options], callback)
Corresponds to [PutItem](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html)
### delete(key, [options], callback)
Corresponds to [DeleteItem](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html)
### update(key, actions, [options], callback)
### update(jsObj, [options], callback)Corresponds to [UpdateItem](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html)
### query(conditions, [options], callback)
Corresponds to [Query](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html)
### scan([conditions], [options], callback)
Corresponds to [Scan](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html)
### batchGet(keys, [options], [tables], callback)
Corresponds to [BatchGetItem](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html)
### batchWrite([operations], [tables], callback)
Corresponds to [BatchWriteItem](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html)
### createTable(readCapacity, writeCapacity, [indexes], [options], callback)
Corresponds to [CreateTable](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_CreateTable.html)
### updateTable(readCapacity, writeCapacity, [options], callback)
Corresponds to [UpdateTable](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateTable.html)
### describeTable([options], callback)
Corresponds to [DescribeTable](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html)
### deleteTable([options], callback)
Corresponds to [DeleteTable](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteTable.html)
### listTables([options], callback)
Corresponds to [ListTables](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ListTables.html)
### increment(key, attr, [incrAmt], [options], callback)
Helper to increment an attribute by a certain amount
### mapToDb(jsObj)
Maps a JavaScript object to a DynamoDB-friendly object
### mapFromDb(dbItem)
Maps a DynamoDB object to a JavaScript object
### mapAttrToDb(val, [key], [jsObj])
Maps an individual attribute/value to a DynamoDB-friendly attribute
### mapAttrFromDb(val, [key], [dbItem])
Maps an individual DynamoDB attribute to a JavaScript value
Installation
------------With [npm](http://npmjs.org/) do:
```
npm install dynamo-table
```Thanks
------Thanks to [@jed](https://github.com/jed) for his lightweight
[dynamo-client](https://github.com/jed/dynamo-client) lib!