DanielHreben/sequelize-transparent-cache

View on GitHub
packages/sequelize-transparent-cache/src/methods/instance.js

Summary

Maintainability
A
0 mins
Test Coverage
const cache = require('../cache')

function instanceMethods (client, instance) {
  return {
    client () { return client },
    save () {
      return instance.save.apply(instance, arguments)
        .then(instance => cache.save(client, instance))
    },
    update () {
      return instance.update
        .apply(instance, arguments)
        .then(instance => cache.save(client, instance))
    },
    reload () {
      return instance.reload
        .apply(instance, arguments)
        .then(instance => cache.save(client, instance))
    },
    destroy () {
      return instance.destroy.apply(instance, arguments)
        .then(() => cache.destroy(client, instance))
    },
    clear () {
      return cache.destroy(client, instance)
    }
  }
}

module.exports = instanceMethods