{"size": 671, "ext": "js", "max_stars_repo_path": "packages/sequelize-models/lib/createModel.js", "max_stars_repo_name": "AlfieriChou/galen", "max_stars_repo_stars_event_min_datetime": "2020-04-06T16:56:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-21T07:46:48.000Z", "max_issues_repo_path": "packages/sequelize-models/lib/createModel.js", "max_issues_repo_name": "AlfieriChou/galen", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/sequelize-models/lib/createModel.js", "max_forks_repo_name": "AlfieriChou/galen", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.6451612903, "max_line_length": 70, "alphanum_fraction": 0.5707898659}
const { jsonToModel } = require('./common')

module.exports = ({
  properties, modelName, tableName, plugins
}, sequelize) => {
  const options = {
    ...plugins,
    underscored: true,
    tableName
  }
  // indexes
  const indexes = Object.keys(properties).reduce((acc, key) => {
    // TODO: index
    // if (properties[key].index) {
    //   return [...acc, {}]
    // }
    if (properties[key].unique) {
      return [...acc, {
        unique: true,
        fields: [key]
      }]
    }
    // TODO: full_text
    return acc
  }, [])
  if (indexes.length) {
    options.indexes = indexes
  }
  return sequelize.define(modelName, jsonToModel(properties), options)
}
