feathers-sequelize
Advanced tools
Comparing version 3.1.0 to 3.1.1
# Change Log | ||
## [v3.1.0](https://github.com/feathersjs-ecosystem/feathers-sequelize/tree/v3.1.0) (2018-03-27) | ||
[Full Changelog](https://github.com/feathersjs-ecosystem/feathers-sequelize/compare/v3.0.2...v3.1.0) | ||
**Merged pull requests:** | ||
- Support params.query in update\(\) [\#189](https://github.com/feathersjs-ecosystem/feathers-sequelize/pull/189) ([TimNZ](https://github.com/TimNZ)) | ||
## [v3.0.2](https://github.com/feathersjs-ecosystem/feathers-sequelize/tree/v3.0.2) (2018-03-25) | ||
@@ -4,0 +11,0 @@ [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-sequelize/compare/v3.0.1...v3.0.2) |
{ | ||
"name": "feathers-sequelize", | ||
"description": "A service adapter for Sequelize an SQL ORM", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"homepage": "https://github.com/feathersjs-ecosystem/feathers-sequelize", | ||
@@ -63,3 +63,3 @@ "main": "lib/", | ||
"lodash.omit": "^4.3.0", | ||
"uberproto": "^1.1.2" | ||
"uberproto": "^2.0.0" | ||
}, | ||
@@ -66,0 +66,0 @@ "devDependencies": { |
@@ -167,5 +167,5 @@ # feathers-sequelize | ||
function (context) { | ||
if (hook.params.query.include) { | ||
const AssociatedModel = hook.app.services.fooservice.Model; | ||
hook.params.sequelize = { | ||
if (context.params.query.include) { | ||
const AssociatedModel = context.app.services.fooservice.Model; | ||
context.params.sequelize = { | ||
include: [{ model: AssociatedModel }] | ||
@@ -190,3 +190,3 @@ }; | ||
For more information, follow up up in the [Sequelize documentation for associations](http://docs.sequelizejs.com/manual/tutorial/associations.html)and [this issue](https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/20). | ||
For more information, follow up up in the [Sequelize documentation for associations](http://docs.sequelizejs.com/manual/tutorial/associations.html) and [this issue](https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/20). | ||
@@ -242,3 +242,62 @@ ## Querying | ||
## Testing sequelize queries in isolation | ||
If you wish to use some of the more advanced features of sequelize, you should first test your queries in isolation (without feathers). Once your query is working, you can integrate it into your feathers app. | ||
### 1. Build a test file | ||
Creat a temporary file in your project root like this: | ||
```js | ||
// test.js | ||
const app = require('./src/app'); | ||
// run setup to initialize relations | ||
app.setup(); | ||
const seqClient = app.get('sequelizeClient'); | ||
const SomeModel = seqClient.models['some-model']; | ||
const log = console.log.bind(console); | ||
SomeModel.findAll({ | ||
/* | ||
* Build your custom query here. We will use this object later. | ||
*/ | ||
}).then(log).catch(log); | ||
``` | ||
And then run this file like this: | ||
``` | ||
node test.js | ||
``` | ||
Continue updating the file and running it until you are satisfied with the results. | ||
### 2. Integrate the query using a "before" hook | ||
Once your have your custom query working to your satisfaction, you will want to integrate it into your feathers app. Take the guts of the `findAll` operation above and create a "before" hook: | ||
```js | ||
function buildCustomQuery(context) { | ||
context.params.sequelize = { | ||
/* | ||
* This is the same object you passed to "findAll" above. | ||
* This object is *shallow merged* onto the underlying query object | ||
* generated by feathers-sequelize (it is *not* a deep merge!). | ||
* The underlying data will already contain the following: | ||
* - "where" condition based on query paramters | ||
* - "limit" and "offset" based on pagination settings | ||
* - "order" based $sort query parameter | ||
* You can override any/all of the underlying data by setting it here. | ||
* This gives you full control over the query object passed to sequelize! | ||
*/ | ||
}; | ||
} | ||
someService.hooks({ | ||
before: { | ||
find: [buildCustomQuery] | ||
} | ||
}); | ||
``` | ||
## Migrations | ||
@@ -245,0 +304,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
99913
485
+ Addeduberproto@2.0.6(transitive)
- Removeduberproto@1.2.0(transitive)
Updateduberproto@^2.0.0