dynazord
v1.5.2
Published
DynamoDB NodeJS ORM
Downloads
17
Maintainers
Readme
DynamoDB NodeJS ORM, inspired by similar ORMs like Mongoose & Sequelize.
const dynazord = require('dynazord');
const users = dynazord.createModel({
tableName: 'dynazord-test-users',
keySchema: {
hash: 'email',
},
properties: {
email: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
avatar: {
type: String,
},
role: {
type: String,
enum: [ 'ADMIN', 'MODERATOR', 'EDITOR', 'USER' ],
default: () => 'USER',
},
},
});
const user = await users.create({
email: '[email protected]',
name: 'James D',
avatar: 'https://github.com/jdrydn.png',
});
console.log(user);
// { email: '[email protected]',
// name: 'James D',
// avatar: 'https://github.com/jdrydn.png'
// role: 'USER' }
const user = await users.get({ email: '[email protected]' });
console.log(user);
// { email: '[email protected]',
// name: 'James D',
// avatar: 'https://github.com/jdrydn.png'
// role: 'USER' }
const user = await users.update({ role: 'EDITOR' }, { email: '[email protected]' });
console.log(user);
// { email: '[email protected]',
// name: 'James D',
// avatar: 'https://github.com/jdrydn.png'
// role: 'EDITOR' }
const user = await users.delete({ email: '[email protected]' });
console.log(user);
// true
This library is designed to simplify interaction with DynamoDB, offering more traditional CRUD methods instead of learning DynamoDB's getItem
/putItem
methods. You can also write functions to validate properties on objects & add other hooks to transform data to suit your needs.
Features
- Create schemas for items in DynamoDB, with validation & hooks to transform data on read & write.
- Read/write methods supporting create, read, update, delete & upsert.
- Bulk read/write methods supporting create, read, update, delete & upsert.
- Transactional read/write methods supporting create, read, update, delete & upsert.
- Query & scan support, following DynamoDB principles.
- "OneTable" support, where models can share the same DynamoDB table underneath.
Installation
$ npm install --save dynazord
Documentation
Development
- Documentation is stored in Git, alongside code, therefore as code changes so should the documentation!
- All major work should be in feature branches, include tests & finish with a PR into
master
. - To run tests, fire up
amazon/dynamodb-local
docker run --rm -d --name dynamodb -p 8000:8000 amazon/dynamodb-local
- Please take note of the differences between the production AWS DynamoDB platform & local Docker container.
Any questions or suggestions please open an issue.