feathers-sequelize
Advanced tools
Comparing version 4.0.8 to 4.1.0
# Change Log | ||
## [v4.0.8](https://github.com/feathersjs-ecosystem/feathers-sequelize/tree/v4.0.8) (2019-01-10) | ||
[Full Changelog](https://github.com/feathersjs-ecosystem/feathers-sequelize/compare/v4.0.7...v4.0.8) | ||
**Merged pull requests:** | ||
- Make sure that queries with id property work properly [\#271](https://github.com/feathersjs-ecosystem/feathers-sequelize/pull/271) ([daffl](https://github.com/daffl)) | ||
- Update @feathersjs/adapter-commons to the latest version 🚀 [\#270](https://github.com/feathersjs-ecosystem/feathers-sequelize/pull/270) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) | ||
## [v4.0.7](https://github.com/feathersjs-ecosystem/feathers-sequelize/tree/v4.0.7) (2018-12-29) | ||
@@ -4,0 +12,0 @@ [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-sequelize/compare/v4.0.6...v4.0.7) |
@@ -27,12 +27,20 @@ const errors = require('@feathersjs/errors'); | ||
constructor (options) { | ||
if (!options.Model) { | ||
throw new Error('You must provide a Sequelize Model'); | ||
let Sequelize; | ||
if (options.Model) { | ||
Sequelize = options.Model.sequelize.Sequelize; | ||
} else if (options.Sequelize) { | ||
Sequelize = options.Sequelize; | ||
} else { | ||
throw new Error('You must provide a Sequelize Model or the Sequelize class'); | ||
} | ||
const defaultOps = defaultOperators(options.Model.sequelize.Sequelize.Op); | ||
const defaultOps = defaultOperators(Sequelize.Op); | ||
const operators = Object.assign(defaultOps, options.operators); | ||
const whitelist = Object.keys(operators).concat(options.whitelist || []); | ||
const { primaryKeyAttributes } = options.Model; | ||
const id = typeof primaryKeyAttributes === 'object' && primaryKeyAttributes[0] !== undefined | ||
? primaryKeyAttributes[0] : 'id'; | ||
super(Object.assign({ | ||
id: 'id', | ||
id, | ||
operators, | ||
@@ -49,6 +57,14 @@ whitelist | ||
get Model () { | ||
if (!this.options.Model) { | ||
throw new Error('The Model getter was called with no Model provided in options!'); | ||
} | ||
return this.options.Model; | ||
} | ||
getModel () { | ||
getModel (params) { | ||
if (!this.options.Model) { | ||
throw new Error('getModel was called without a Model present in the constructor options and without overriding getModel! Perhaps you intended to override getModel in a child class?'); | ||
} | ||
return this.options.Model; | ||
@@ -55,0 +71,0 @@ } |
{ | ||
"name": "feathers-sequelize", | ||
"description": "A service adapter for Sequelize an SQL ORM", | ||
"version": "4.0.8", | ||
"version": "4.1.0", | ||
"homepage": "https://github.com/feathersjs-ecosystem/feathers-sequelize", | ||
@@ -6,0 +6,0 @@ "main": "lib/", |
@@ -46,4 +46,5 @@ # feathers-sequelize | ||
- `Model` (**required**) - The Sequelize model definition | ||
- `id` (*optional*, default: `'id'`) - The name of the id field property. | ||
- `id` (*optional*, default: primary key of the model) - The name of the id field property. Will use the first property with `primaryKey: true` by default. | ||
- `raw` (*optional*, default: `true`) - Runs queries faster by returning plain objects instead of Sequelize models. | ||
- `Sequelize` (*optional*, default: `Model.sequelize.Sequelize`) - The Sequelize instance | ||
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service | ||
@@ -50,0 +51,0 @@ - `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size |
80944
389
539