
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@chocolatesoup/joiful-dynamodb
Advanced tools
Project to interact with Dynamodb having some basic ORM functions like basic relations and validations.
Joiful-Dynamo uses Typescript Decorators to easily let developers to manage data models. This IS NOT a complete ORM, but a facilitator to make the experience of using AWS DynamoDB easier and with less code repetition. This packages was developed with the Single Table Adjacency List Design Pattern in mind.
The decorators includes:
See the full docs at https://chocolate-soup-inc.github.io/joiful-dynamo/.
Using AWS DynamoDB is always a very challenging and verbose experience. Some packages achieved very good experiences when interacting with data, like TypeORM and Sequelize but they don't connect to DynamoDB. Some dynamodb libraries are awesome (like DynamoDB Toolbox) but misses some basic functionality like data validation and transforming. Also, if you want to use a one table design it gets even harder to find complete solutions. So, joiful-dynamo connects the experience of using Joi as a validation library to a better experience with dynamodb.
As this library was architected with single table design in mind, if you want to use a multi table design, use it at your own risk.
npm i --save @chocolatesoup/joiful-dynamodb
npm install reflect-metadata --save
npm install @types/node --save-dev
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
You may also need to enable es6 in the lib section of compiler options, or install es6-shim from @types.
import {
Entity,
aliases,
aliasTo,
props,
table,
validate,
} from '@chocolatesoup/joiful-dynamo';
import * as Joi from 'joi';
@table('test-table')
class TestModel extends Entity {
@prop({ primaryKey: true });
@validate(Joi.string().required())
@aliases(['primary'])
pk: string;
@prop()
@validate(Joi.string().trim().required())
name: string;
@prop()
@aliasTo('name')
fullName: string;
@prop({ createdAt: true })
_createdAt: string;
@prop({ updatedAt: true })
_updatedAt: string;
}
const instance = new TestModel({
pk: '1',
fullName: ' test name ',
extraAttribute: 'extra',
});
// this should be inside an async function
await instance.create();
/*
Data saved to DB:
{
pk: 'TestModel-1',
name: 'test name',
extraAttribute: 'extra',
_createdAt: '2022-02-07T22:43:30.344Z',
_updatedAt: '2022-02-07T22:43:30.344Z',
_entityName: 'TestModel',
}
*/
const invalidInstance = new TestModel({
name: 'Name',
});
console.log(invalidInstance.valid) // false
invalidInstance.create() // Throws error.
const dbInstance = await TestModel.getItem({ pk: '1' });
dbInstance.name = '123'
dbInstance.update();
const scanInstances = await TestModel.scan(); // scanAll also available
console.log(scanInstances.items) // Array of test instances
await scanInstances.next() // Load next page
console.log(scanInstances.items) // Array with ALL test instances
console.log(scanInstances.lastPageItems) // Array with last page instances
const queryOpts = {
IndexName: 'byEntity',
KeyConditionExpression: '_entityName = :e',
ExpressionAttributeValues: {
':e': 'TestModel',
},
};
const queryInstances = await TestModel.query(queryOpts); // queryAll also available
console.log(queryInstances.items) // Array of test instances
await queryInstances.next() // Load next page
console.log(queryInstances.items) // Array with ALL test instances
console.log(queryInstances.lastPageItems) // Array with last page instances
For more examples and full docs, access https://chocolate-soup-inc.github.io/joiful-dynamo/.
This package definitely has a lot of space for new features and improvements, so please contribute! =)
Contributions, ideas and bug reports are welcome and greatly appreciated. Please add issues for suggestions and bug reports or create a pull request.
FAQs
Project to interact with Dynamodb having some basic ORM functions like basic relations and validations.
We found that @chocolatesoup/joiful-dynamodb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.