GenericJSONCache

Contains a set of simple methods to handle the redis ReJSON type

new GenericJSONCache()
Static Members
parseCacheString(cacheString)
isCached(keyName, args?)
_getKeyNamesCache(searchKey, commands = redis)
_getCache(keyName, attrs, commands = redis)
_getListCache(keyNames, attrs, commands = redis.multi())
_setCache(keyName, object, attr, commands)
_delete(keyName)

GenericModel

Contains a set of chewed methods to handle documents

new GenericModel()
Static Members
QUERY_ATTR_NAMES
getFilterObject(params)
getAll(params)
getCount(params)
getOne(params)
saveOrUpdate(object)

genericSchema

Besides preparing GenericModel to be happily inherited as a mongoose.Schema super class:

genericSchema(schema: mongoose.Schema, options: Object, dbConnectFunction: Function?): Object
Parameters
schema (mongoose.Schema) The mongoose schema object
options (Object) The schema options
dbConnectFunction (Function?) The db connect function (for Lambda and alikes, see https://mongoosejs.com/docs/lambda.html )
Returns
Object: The [ GenericModel ] GenericModel and its [ Schema ] https://mongoosejs.com/docs/api/schema.html#schema_Schema
Example
// db.js
const mongoose = require('mongoose')

module.exports = () => mongoose.connect(process.env.MONGODB_URL)

// You.js
const db = require('./db')

const SCHEMA = {
   name: String,
   life: Number,
   ...
}

const OPTIONS = {
   _id     : true,
   strict  : false,
   ...
}

const { GenericModel, GenericSchema } = require('lib/models/GenericSchema')(SCHEMA, OPTIONS, db)

module.exports = mongoose.model('You', GenericSchema)

// file.js
const You = require('./You')

You.save({ name: 'you' })

const you = await You.getOne({ name: 'you' })
// {
//   _id : idRandom,
//   name: 'you'
// }

you.name = 'arpel'

await you.save()

await You.getAll()
// [(1)]

await You.find()
// [(1)]
// You.js
const { GenericModel, GenericSchema } = require('lib/models/GenericSchema')(SCHEMA, OPTIONS)

class You extends GenericModel {
   arpel() {
     this.name = 'arpel'

     return this.save()
   }

   static async arpel() {
     return You.save({ name: 'arpel' })
   }
}

module.exports = mongoose.model('You', GenericSchema)

// file.js
const You = require('./You')

const you = new You()

await you.arpel()
await You.arpel()

You.getCount({ name: 'arpel' })
// 2

You.count({ name: 'arpel' })
// 2