redis-crud
A very simple library for generating models that uses REDIS as the database and provides the basic CRUD functionality.
Usage
const redis = ;const db = redis;const generateModel = generateModel; const UserModel = ; // Insert a new record and get the serial id using promiseUserModel; // Retrieve the recordUserModel; // Update the recordUserModel; // Delete the recordUserModel; // Iterate through all the records, providing the number of records to// retrieve on each iterationconst iterator = UserModel;iteratornext;
Using hooks
const UserModel = ; // The hook invoked before a new record is inserted, with the object instance// that is being inserted. Throw an error here to avoid the record from// being insertedUserModel { }; // The hook invoked after the record is inserted. The hook is provided with// the new id of the record. Do the post record insertion operations here,// like create secondary records for easy data retrieval based on certain// propertiesUserModel { }; // The hook invoked before the record is updated. The obj provides the// properties that are going to be updated (either new or old). Throwing an// exception here will stop the record from being updatedUserModel { }; // The hook invoked after the record is updated. The parameters are same as// the ones provided in beforeUpdateUserModel { }; // The hook invoked before the record is deleted. The obj provides the object// in the database that is going to be removed. Throwing an exception here will// stop the record from being deletedUserModel { }; // The hook invoked after the record is deleted.UserModel { };