Storage class is a parent class that it can be use like orm approach. Create model class and extend to Storage parent then use it for different data stores.
Example model class:
import Storage from "./Storage";
export class FrameModel extends Storage {
constructor() {
super('frames')
}
}
Note: You have define data store name to
super
keyword.
Instantiation:
const frame = new FrameModel;
frame.getAll().then(data => {
// do something...
});
That's it.
Parameter: Object
Return: Promise<Any>
Create or update an item.
Example:
const item = {
name: 'Birthday',
type: 'Crew'
};
frame.save(item).then((err, numReplaced, upsert) => {
// do something...
});
Note: if update the existing data, it will returns parameters in the examples.
Remove items.
Parameter: Object
Return: Promise<Any, Number>
(number of deleted items)
Example:
frame.remove({_id: 'aaa44r446464'}).then((err, numDeleted) => {
// do something...
})
Bulk save operation.
Parameter: Array[]
Return: Promise<Any, Array[]>
const items = [
{
name: 'Birthday',
type: 'Crew'
},
{
name: 'UM Passengers',
type: 'passenger'
}
];
frame.blukSave(items).then((err, newDocs) => {
// do something...
});
Count items.
Parameter: Object
Return: Promise<Any, Number>
Example:
frame.count({type: 'crew'}).then((err, count) => {
// do something...
});
Find items.
Parameter: Object
Return: Promise<Any, Array[]>
Example:
frame.find({type: 'crew'}).then((err, docs) => {
// do something...
});
Access to the following methods.