Advanced, database agnostic ODM
Sometimes your application is not a simple to-do list and you need to write complex business logic. Rather than strictly predefined CRUD methods and hooks, enterprise-model is a set of tools which you can use to write your own logic, data sources and reusable behaviours.
- Scheme (inheritable, with nested models)
- Validations (extendable validations and sanitizers)
- Defaults (inheritable default settings)
- Methods (inheritable instance and constructor methods)
- Queries (inheritable, extendable and cacheable query builder methods)
- Hooks (inheritable and extendable)
- Relations with integrity maintaining hooks
- Data sources with optimistic locks (Memory, Json file, Mongo, Rest, Elastic search)
- Caching (synchronize workers' cache across nodejs cluster)
- Behaviours (Orderable, Tree)
Installation
npm install enterprise-model
Usage
var Model = ; /* * create employee model, which: * 1. is stored in mongo database * 2. is in tree structure * 3. is orderable * 4. can handle process of changing job - it is not just a simple update, * it has to be confirmed by HR department */var Employee = Model; // define connection details by extending inherited defaultsEmployee; // now, add hookable methodEmployeeprototypechangeJob = Employee; // register "beforeChangeJob" listenerEmployee; // init model, this will ensure indexes or do some work to init datastoreEmployee; // now we can get employee and change his jobEmployee; // if you need to define a new type of employee, just inherit it from Employee.// It will inherit all methods including registered events like "beforeJobChange".var SuperEmployee = Model;