Skip to content

Instantly share code, notes, and snippets.

@banyudu
Created March 18, 2017 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banyudu/5c6961ca7d50b8e5be8a0d504a2d3dcb to your computer and use it in GitHub Desktop.
Save banyudu/5c6961ca7d50b8e5be8a0d504a2d3dcb to your computer and use it in GitHub Desktop.
Sequelize model integrates with cache
'use strict';
const fs = require('fs');
module.exports = function(sequelize, DataTypes) {
const tableName = 'something';
const attr = JSON.parse(fs.readFileSync(__dirname + `/attributes/${tableName}`));
const Something = sequelize.define('Something',attr, {
classMethods: {
getCacheFields: () => { return ['field1', 'field2', 'field3'] } // fields you want to cache
},
tableName: tableName,
underscored: true,
createdAt: false,
updatedAt: false
});
return Something;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment