daymon
v1.2.27
Published
ORM for DynamoDB
Downloads
100
Readme
** This is in early development so new versions will continuously be published.
*** Usage
var options = {
convertEmptyStringToNull: true,
timeStamps: {
update: 'dateUpdated',
create: 'dateCreated'
},
awsConfig: {
region: 'aws region'
accessKeyId: 'aws id',
secretAccessKey: 'aws secret',
dynamodb: {
endpoint: 'some endpoint'
}
}
}
var daymon = require('daymon')(options);
var tableName = 'users'
var Model = daymon(tableName);
The awsConfig property on the options object is required. The convertEmptyStringToNull converts empty strings to null values, as dynamodb does not accept empty strings as values. convertEmptyStringToNull is false by default and instead of converting empty strings to null, the property will not be updated.
To automatically set timestamps when calling save() or update(), set timeStamps.create and/or timeStamps.update. The values will be Date.now(). If these keys are set on individual saves or updates before calling save() or update(), the automatic timestamp will not override these values.
*** Query
Model.query(options) => promise;
The options object has the be an object that has a key of either primary index hash key or a secondary index hash key. Error will be thrown otherwise.
You can either pass single value or an array of values:
var queryOptions = {
id: 'some id'
}
or
var queryOptions = {
id: ['id1', 'id2', 'id3']
}
*** Scan
Model.scan(options) => promise;
The options object has to be an object. Keys and values can be anything.
*** instance.save();
new Model(objectToSave).save() => promise;
If the objectToSave has no primary index hash key, a unique one will be generated as a String. This will most probably change at some point.
If the objectToSave already has a primary index hash key, an update will be performed instead.
*** instance.update()
new Model(objectWithHashKey).update() => promise
Updates an existing object. It uses dynamodb.documentClient.update and will create a new item if it is not already there.