A simple Amazon DynamoDB object modeler for Node.js. Dino is designed to leverage the fast (and inexpensive) parts of the DynamoDB API by default. The complete DynamoDB client is exposed for extensibility.
var dino = require('dino');
dino.connect({
accessKeyId: 'YOUR_KEY',
secretAccessKey: 'YOUR_SECRET',
region: 'us-east-1'
});
var Forum = dino.model({
schema: dino.schema({
table: 'forums',
attributes: {
name: dino.types.string,
category: dino.types.string
},
key: {
hash: 'name'
}
})
});
var forum = Forum.create({
name: 'Amazon DynamoDB',
category: 'Amazon Web Services'
});
forum.save();
$ npm install dino
connect()
connection.client
connection.create()
schema()
schema.createTable()
type()
model()
Model.create()
Model.findOne()
Model.find()
Model.destroy()
model.set()
model.get()
model.save()
model.destroy()
model.toJSON()
collection.toJSON()
collection.models
Sets the default DynamoDB client for your application. Alternatively, you can omit this and use environment variables.
dino.connect({
accessKeyId: 'YOUR_KEY',
secretAccessKey: 'YOUR_SECRET',
region: 'us-east-1'
});
accessKeyId
(required)secretAccessKey
(required)region
(required)
The default DynamoDB client.
Creates a DynamoDB client to be used at your will.
var client = dino.connection.create({
accessKeyId: 'YOUR_OTHER_KEY',
secretAccessKey: 'YOUR_OTHER_SECRET',
region: 'us-east-1'
});
accessKeyId
(required)secretAccessKey
(required)region
(required)
Creates a schema.
var forumSchema = dino.schema({
table: 'forums',
attributes: {
name: dino.types.string,
date_created: dino.types.date,
author: dino.types.string
},
key: {
hash: 'name',
range: 'date_created',
secondary: 'author'
}
});
table
(required)attributes
(required)key
(required)keyDelimiter
boolean
date
id
number
object
string
Creates a table in DynamoDB.
forumSchema.createTable({
readUnits: 5,
writeUnits: 2
}, function(err){ });
client
readUnits
writeUnits
Creates a schema type.
var myType = dino.type({
defaultValue: null,
serialize: function (val) { return val; },
deserialize: function (val) { return val; },
toJSON: function (val) { return val; }
});
defaultValue
serialize
deserialize
toJSON
Creates a Model object. Use Model objects to create and query models.
var Forum = dino.model({
schema: forumSchema
});
schema
(required)client
Creates a model.
var forum = Forum.create({
name: 'Amazon DynamoDB',
category: 'Amazon Web Services'
});
Queries DynamoDB for a single model.
Forum.findOne({
name: 'Amazon DynamoDB'
}, function(err, forum, units){ });
Queries DynamoDB for a collection of models.
Reply.find({
match: {
forum_name: 'Amazon DynamoDB',
thread_name: 'DynamoDB Thread 1'
}
take: 10
}, function(err, replies, units){ });
match
(required)skip
take
sortBy
Deletes a model from DynamoDB.
Forum.destroy({
name: 'Amazon DynamoDB'
}, function(err, units){ });
Sets the model's attributes.
forum.set({
name: 'Amazon S3'
});
Gets the model's attributes.
forum.get('name'); // 'Amazon S3'
Saves the model to DynamoDB.
forum.save(function(err, units){ });
Deletes the model from DynamoDB.
forum.destroy(function(err, units){ });
Returns the JSON serialized attributes of the model.
forum.toJSON();
Returns an array where each model in the collection has been JSON serialized.
replies.toJSON();
The raw array of models in the collection.
replies.models;
Install the dependencies and run.
$ npm install
$ npm test
0.3.3 — May 9, 2013
- Applied
_.bindAll
to Model and Schema objects for easier flow control with async.
0.3.2 — May 8, 2013
- Fixed regression where
Model.findOne()
would fail silently on tables w/o a range key.
0.3.1 — May 8, 2013
- Fixed regression where instance members weren't being assigned on
Model.create()
.
0.3.0 — May 5, 2013
- Migrated to DynamoDB API version 2012-08-10, which allows for secondary indexes. You can now query, sort and destroy by secondary index. Review the documentation on
find()
,findOne
, anddestroy()
to see the changes to the API.