Crud Mongoose Connector
Description
Create an object with CRUD operations from a mongoose model.
Installation
npm i --save crud-mongoose-connector
Usage
;; interface TestModel _id: string; name: string; anotherField?: Date; const testSchema = anotherField: Date name: type: String required: true ;const testModel = mongoose; const testCRUD: MongooseCrudModel<TestModel> = ; // then you can use testCRUD to create / read / update / deletetestCRUD; // returns a Promise with the newly created objecttestCRUD; // returns a Promise with ONE object or throws an error if no object foundtestCRUD; // returns a Promise with an array of all found object corresponding to the querytestCRUD; // data is ignored if id is providedtestCRUD; // returns a Promise with the updated elementtestCRUD; // returns a Promise with the deleted element
Notes
You can use mongoose-plugin-events
with this library to have the model emit the
create/update/delete events.