Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: perf, restructuring, rm _getOrFind, rm params.$returning, use instance methods #429

Merged
merged 30 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
645255e
perf: set id, check necessity of $in and $and
fratzinger Feb 28, 2024
1789383
fix: explicit NullableId check against null, not just truethy
fratzinger Feb 28, 2024
640b4da
Use object instead of function
DaddyWarbucks Feb 28, 2024
a83977f
Use object instead of function
DaddyWarbucks Feb 28, 2024
6cd108d
Simplfy paramsToAdapter
DaddyWarbucks Feb 28, 2024
62bd29f
Faster count
DaddyWarbucks Feb 28, 2024
cae4204
Limit get method to one result
DaddyWarbucks Feb 28, 2024
40faf74
Use SQL select, branch patch and remove.
DaddyWarbucks Feb 29, 2024
580ee7f
Set attributes for count
DaddyWarbucks Feb 29, 2024
fc0ed82
Remove property
DaddyWarbucks Feb 29, 2024
a4331e9
fix: $returning, order, _update
fratzinger Feb 29, 2024
d88862f
Standardize create and update
DaddyWarbucks Mar 1, 2024
3ee0e7f
Standardize returning
DaddyWarbucks Mar 1, 2024
af4be00
Optimize adapters, update tests
DaddyWarbucks Mar 1, 2024
d63a7e8
Fix spread
DaddyWarbucks Mar 1, 2024
7c78680
Cleanup @fratzinger suggestions
DaddyWarbucks Mar 1, 2024
d36f632
fix: rm option returning for single calls, sort for multi patch
fratzinger Mar 10, 2024
f75b4f2
Fix update/patch with includes
DaddyWarbucks Mar 14, 2024
f933f4c
Update multi patch sort
DaddyWarbucks Mar 14, 2024
a55ac55
Use instance.set
DaddyWarbucks Mar 14, 2024
619690c
Fix typo
DaddyWarbucks Mar 15, 2024
9005ce0
Remove applyScope and update paramsToAdapter
DaddyWarbucks Mar 27, 2024
d720c5c
Remove _getOrFind
DaddyWarbucks Mar 30, 2024
9406256
Make update and patch more similar return code
DaddyWarbucks Mar 30, 2024
f8eb846
Fix option:raw for updates
DaddyWarbucks Mar 30, 2024
8fc41d2
Don't set id
DaddyWarbucks Mar 30, 2024
0363acd
Use instance in update
DaddyWarbucks Mar 30, 2024
b7a01b6
Update docs
DaddyWarbucks Mar 31, 2024
8293f9c
docs: migrate to esm imports
fratzinger May 12, 2024
3655084
fix: renaming sequelize -> sequelizeOptions & rm ts-ignore
fratzinger May 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A [Feathers](https://feathersjs.com) database adapter for [Sequelize](http://seq
- [Querying a nested column](#querying-a-nested-column)
- [Working with Sequelize Model instances](#working-with-sequelize-model-instances)
- [Validation](#validation)
- [Errors](#errors)
- [Testing sequelize queries in isolation](#testing-sequelize-queries-in-isolation)
- [1. Build a test file](#1-build-a-test-file)
- [2. Integrate the query using a "before" hook](#2-integrate-the-query-using-a-before-hook)
Expand Down Expand Up @@ -162,7 +163,7 @@ By default, all `feathers-sequelize` operations will return `raw` data (using `r
- associated data loads a bit differently
- ...and several other issues that one might not expect

Don't worry! The solution is easy. Please read the guides about [working with model instances](#working-with-sequelize-model-instances).
Don't worry! The solution is easy. Please read the guides about [working with model instances](#working-with-sequelize-model-instances). You can also pass `{ raw: true/false}` in `params.sequelize` to change the behavior per service call.

### Working with MSSQL

Expand Down Expand Up @@ -313,8 +314,6 @@ For more information, follow up up in the [Sequelize documentation for associati

Additionally to the [common querying mechanism](https://docs.feathersjs.com/api/databases/querying.html) this adapter also supports all [Sequelize query operators](http://docs.sequelizejs.com/manual/tutorial/querying.html).

> **Note**: This adapter supports an additional `$returning` parameter for patch and remove queries. By setting `params.$returning = false` it will disable feathers and sequelize from returning what was changed, so mass updates can be done without overwhelming node and/or clients.

### Querying a nested column

To query based on a column in an associated model, you can use Sequelize's [nested column syntax](https://sequelize.org/master/manual/eager-loading.html#complex-where-clauses-at-the-top-level) in a query. The nested column syntax is considered an operator by Feathers, and so each such usage has to be [whitelisted](#options-whitelist).
Expand Down Expand Up @@ -376,13 +375,29 @@ It is highly recommended to use `raw` queries, which is the default. However, th

Sequelize by default gives you the ability to [add validations at the model level](http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations). Using an error handler like the one that [comes with Feathers](https://github.com/feathersjs/feathers-errors/blob/master/src/error-handler.js) your validation errors will be formatted nicely right out of the box!

## Errors

Errors do not contain Sequelize specific information. The original Sequelize error can be retrieved on the server via:

```js
const { ERROR } = require('feathers-sequelize');

try {
await sequelizeService.doSomethign();
} catch(error) {
// error is a FeathersError
// Safely retrieve the Sequelize error
const sequelizeError = error[ERROR];
}
```

## 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:
Create a temporary file in your project root like this:

```js
// test.js
Expand Down Expand Up @@ -616,32 +631,6 @@ In the unfortunate case where you must revert your app to a previous state, it i
1. Revert your code back to the previous state
1. Start your app

### Migrating

`feathers-sequelize` 4.0.0 comes with important security and usability updates.

> __Important:__ For general migration information to the new database adapter functionality see [crow.docs.feathersjs.com/migrating.html#database-adapters](https://crow.docs.feathersjs.com/migrating.html#database-adapters).

The following breaking changes have been introduced:

- All methods now take `params.sequelize` into account
- All methods allow additional query parameters
- Multiple updates are disabled by default (see the `multi` option)
- Upgraded to secure Sequelize operators (see the [operators](#operators) option)
- Errors no longer contain Sequelize specific information. The original Sequelize error can be retrieved on the server via:

```js
const { ERROR } = require('feathers-sequelize');

try {
await sequelizeService.doSomethign();
} catch(error) {
// error is a FeathersError
// Safely retrieve the Sequelize error
const sequelizeError = error[ERROR];
}
```

## License

Copyright (c) 2022
Expand Down
Loading
Loading