What is dynamoose?
Dynamoose is a modeling tool for Amazon's DynamoDB, inspired by Mongoose. It provides a simple and easy-to-use API for defining schemas, models, and performing CRUD operations on DynamoDB tables.
What are dynamoose's main functionalities?
Schema Definition
Dynamoose allows you to define schemas for your DynamoDB tables. This schema definition helps in structuring the data and enforcing data types.
const dynamoose = require('dynamoose');
const UserSchema = new dynamoose.Schema({
id: String,
name: String,
age: Number
});
Model Creation
Once you have defined a schema, you can create a model. This model will be used to interact with the DynamoDB table.
const User = dynamoose.model('User', UserSchema);
CRUD Operations
Dynamoose provides methods for performing CRUD operations. You can create, read, update, and delete items in your DynamoDB table using the model.
const newUser = new User({
id: '1',
name: 'John Doe',
age: 30
});
newUser.save();
User.get('1').then(user => console.log(user));
User.update({ id: '1' }, { age: 31 });
User.delete('1');
Query and Scan
Dynamoose supports querying and scanning the DynamoDB table. You can use various conditions to filter the data.
User.query('name').eq('John Doe').exec().then(users => console.log(users));
User.scan('age').gt(25).exec().then(users => console.log(users));
Other packages similar to dynamoose
aws-sdk
The AWS SDK for JavaScript provides direct access to DynamoDB and other AWS services. It is more low-level compared to Dynamoose and requires more boilerplate code for operations.
vogels
Vogels is another DynamoDB modeling tool inspired by Mongoose. It offers similar functionalities to Dynamoose but is less actively maintained.
Dynamoose
Dynamoose is a modeling tool for Amazon's DynamoDB (inspired by Mongoose)
Getting Started
Installation
$ npm install dynamoose
Example
Set AWS configurations in enviroment varable:
export AWS_ACCESS_KEY_ID="Your AWS Access Key ID"
export AWS_SECRET_ACCESS_KEY="Your AWS Secret Access Key"
export AWS_REGION="us-east-1"
Here's a simple example:
var dynamoose = require('dynamoose');
var Cat = dynamoose.model('Cat', { id: Number, name: String });
var garfield = new Cat({id: 666, name: 'Garfield'});
garfield.save();
Cat.get(666)
.then(function (badCat) {
console.log('Never trust a smiling cat. - ' + badCat.name);
});
API Docs
The documentation can be found at https://dynamoosejs.com/api.
Change log
Release 0.8
- useNativeBooleans #55
- saveUnknown #125
- Support for multiple indexes defined on the hashkey attribute of the table
- scan.all() #93 #140
- scan.parallel d7f7f77
- TTL support 92994f1
- added schema parsing overrides #145
- populate #137
- Added consistent() to scan. #15 #142
- Default function enhancements #127
- Create required attributes on update #96
- Add typescript typings #123
- Added .count() for Query and Scan #101
- Nested scans #141 #158
Roadmap
Release 0.9
The goal of release 0.9 is to increase the parity with mongoose. The primary purpose will be to come up with a plugin system similar to that of mongoose although not necessarily compatible.
Release 1.0
The main goal of 1.0 will be to improve the code and refactor to ES2015 (ES6). In addition, useNativeBooleans
and useDocumentTypes
will be toggled to make uses of "newer" DynamoDB features by default.