Skip to content

Commit

Permalink
Adds _getRawAttributes()
Browse files Browse the repository at this point in the history
  • Loading branch information
bravo-kernel committed Aug 14, 2019
1 parent 61c13c2 commit fc3b89d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/schema-manager.js
@@ -1,8 +1,14 @@
/* eslint-disable class-methods-use-this */
/* eslint-disable no-underscore-dangle */

const merge = require('lodash.merge');
const StrategyInterface = require('./strategy-interface');

/**
* Private methods.
*/
const _getRawAttributes = Symbol('Private method');

/**
* Private properties.
*
Expand Down Expand Up @@ -54,8 +60,11 @@ class SchemaManager {
if (!(strategy instanceof StrategyInterface))
throw new TypeError("Strategy must implement the 'StrategyInterface'");

// extract sequelize properties
const rawAttributes = this[_getRawAttributes](model);

// all good, import model, generate schema
return '{ dummy: "json schema" }';
return rawAttributes;
}

/**
Expand All @@ -66,6 +75,21 @@ class SchemaManager {
getOptions() {
return privateProperties.get(this).options; // WeakMap
}

/**
* Return the raw properties from a (v4 or v5+) Sequelize model.
*
* @private
* @param {Sequelize.Model} model Instance of Sequelize.Model
* @returns {object} Raw Sequelize attributes.
*/
[_getRawAttributes](model) {
if ('rawAttributes' in model) {
return model.rawAttributes; // v5+
}

return model.attributes; // v4
}
}

module.exports = SchemaManager;

0 comments on commit fc3b89d

Please sign in to comment.