不要怂,就是干,撸起袖子干!

Commit bc6c133c by Sushant

docs: v5.0.0-beta.17

1 parent 4478d74a
......@@ -51,7 +51,6 @@
"./docs/raw-queries.md",
"./docs/migrations.md",
"./docs/upgrade-to-v5.md",
"./docs/upgrade-to-v4.md",
"./docs/legacy.md",
"./docs/whos-using.md",
"./docs/legal.md"
......
......@@ -7,8 +7,8 @@
301 /en/latest /
301 /en/latest/ /
301 /en/latest/docs/getting-started/ /manual/installation/getting-started.html
301 /en/latest/docs/:section/ /manual/tutorial/:section.html
301 /en/latest/docs/getting-started/ /manual/getting-started.html
301 /en/latest/docs/:section/ /manual/:section.html
301 /en/latest/api/sequelize/ /class/lib/sequelize.js~Sequelize.html
301 /en/latest/api/model/ /class/lib/model.js~Model.html
......@@ -22,3 +22,5 @@
301 /en/latest/api/datatypes/ /variable/index.html#static-variable-DataTypes
301 /en/latest/api/deferrable/ /variable/index.html#static-variable-Deferrable
301 /en/latest/api/errors/ /class/lib/errors/index.js~BaseError.html
302 /manual/tutorial/:section.html /manual/:section.html
\ No newline at end of file
......@@ -719,7 +719,7 @@ project.setUsers([user1, user2]).then(() => {
## Advance Concepts
### Scopes
This section concerns association scopes. For a definition of association scopes vs. scopes on associated models, see [Scopes](/manual/tutorial/scopes.html).
This section concerns association scopes. For a definition of association scopes vs. scopes on associated models, see [Scopes](/manual/scopes.html).
Association scopes allow you to place a scope (a set of default attributes for `get` and `create`) on the association. Scopes can be placed both on the associated model (the target of the association), and on the through table for n:m relations.
......
......@@ -164,7 +164,7 @@ Timeline.create({ range: [-Infinity, new Date(Date.UTC(2016, 0, 1))] });
# Extending datatypes
Most likely the type you are trying to implement is already included in [DataTypes](/manual/tutorial/data-types.html). If a new datatype is not included, this manual will show how to write it yourself.
Most likely the type you are trying to implement is already included in [DataTypes](/manual/data-types.html). If a new datatype is not included, this manual will show how to write it yourself.
Sequelize doesn't create new datatypes in the database. This tutorial explains how to make Sequelize recognize new datatypes and assumes that those new datatypes are already created in the database.
......@@ -271,7 +271,7 @@ modules.exports = function sequelizeAdditions(Sequelize) {
// Mandatory, create a postgres-specific child datatype with its own parse
// method. The parser will be dynamically mapped to the OID of pg_new_type.
PgTypes = DataTypes.postgres
PgTypes = DataTypes.postgres
PgTypes.NEWTYPE = function NEWTYPE() {
if (!(this instanceof PgTypes.NEWTYPE)) return new PgTypes.NEWTYPE();
......
......@@ -102,7 +102,7 @@ User.findAll().then(users => {
})
```
You can read more about finder functions on models like `.findAll()` at [Data retrieval](/manual/tutorial/models-usage.html#data-retrieval-finders) or how to do specific queries like `WHERE` and `JSONB` at [Querying](/manual/tutorial/querying.html).
You can read more about finder functions on models like `.findAll()` at [Data retrieval](/manual/models-usage.html#data-retrieval-finders) or how to do specific queries like `WHERE` and `JSONB` at [Querying](/manual/querying.html).
### Application wide model options
......
......@@ -127,7 +127,7 @@ Sequelize.Deferrable.NOT
```
The last option is the default in PostgreSQL and won't allow you to dynamically change
the rule in a transaction. See [the transaction section](/manual/tutorial/transactions.html#options) for further information.
the rule in a transaction. See [the transaction section](/manual/transactions.html#options) for further information.
## Getters & setters
......@@ -666,7 +666,7 @@ sequelize.define('user', {}, {
```
[0]: /manual/tutorial/models-definition.html#configuration
[1]: /manual/tutorial/data-types.html
[0]: /manual/models-definition.html#configuration
[1]: /manual/data-types.html
[3]: https://github.com/chriso/validator.js
[5]: /docs/final/misc#asynchronicity
......@@ -2,7 +2,7 @@
## Data retrieval / Finders
Finder methods are intended to query data from the database. They do *not* return plain objects but instead return model instances. Because finder methods return model instances you can call any model instance member on the result as described in the documentation for [*instances*](/manual/tutorial/instances.html).
Finder methods are intended to query data from the database. They do *not* return plain objects but instead return model instances. Because finder methods return model instances you can call any model instance member on the result as described in the documentation for [*instances*](/manual/instances.html).
In this document we'll explore what finder methods can do:
......
......@@ -178,7 +178,7 @@ const Op = Sequelize.Op
Range types can be queried with all supported operators.
Keep in mind, the provided range value can
[define the bound inclusion/exclusion](/manual/tutorial/data-types.html#range-types)
[define the bound inclusion/exclusion](/manual/data-types.html#range-types)
as well.
```js
......
......@@ -270,7 +270,7 @@ this.Post.hasMany(this.Comment, {
});
```
When calling `post.getComments()`, this will automatically add `WHERE commentable = 'post'`. Similarly, when adding new comments to a post, `commentable` will automagically be set to `'post'`. The association scope is meant to live in the background without the programmer having to worry about it - it cannot be disabled. For a more complete polymorphic example, see [Association scopes](/manual/tutorial/associations.html#scopes)
When calling `post.getComments()`, this will automatically add `WHERE commentable = 'post'`. Similarly, when adding new comments to a post, `commentable` will automagically be set to `'post'`. The association scope is meant to live in the background without the programmer having to worry about it - it cannot be disabled. For a more complete polymorphic example, see [Association scopes](/manual/associations.html#scopes)
Consider then, that Post has a default scope which only shows active posts: `where: { active: true }`. This scope lives on the associated model (Post), and not on the association like the `commentable` scope did. Just like the default scope is applied when calling `Post.findAll()`, it is also applied when calling `User.getPosts()` - this will only return the active posts for that user.
......
# Upgrade to v4
Sequelize v4 is the current release and it introduces some breaking changes. Majority of sequelize codebase has been refactored to use ES2015 features. The following guide lists some of the changes to upgrade from v3 to v4.
## Changelog
Full [Changelog](https://github.com/sequelize/sequelize/blob/b49f936e9aa316cf4a13bade76585acf4d5d8b04/changelog.md) for v4 release.
## Breaking Changes
### Node
To use new ES2015 features, Sequelize v4 requires at least Node v4 or above.
### General
* Counter Cache plugin and consequently the ```counterCache``` option for associations has been removed.
* MariaDB dialect now removed. This was just a thin wrapper around MySQL. You can set ``dialect: 'mysql'`` an d Sequelize should be able to work with MariaDB server.
* `Model.Instance` and `instance.Model` are removed. To access the Model from an instance, simply use [`instance.constructor`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor). The Instance class (`Model.Instance`) is now the Model itself.
* Sequelize now uses an independent copy of bluebird library.
* Promises returned by sequelize are now instances of `Sequelize.Promise` instead of global bluebird `Promise`.
* Pooling library was updated to `v3`, now you will need to call `sequelize.close()` to shutdown the pool.
### Config / Options
* Removed support for old connection pooling configuration keys. Instead of
**Old**
```js
pool: {
maxIdleTime: 30000,
minConnections: 20,
maxConnections: 30
}
```
**New**
```js
pool: {
idle: 30000,
min: 20,
max: 30
}
```
* Removed support for `pool: false`. To use a single connection, set `pool.max` to 1.
* Removed support for ``referencesKey``, use a references object
```js
references: {
key: '',
model: ''
}
```
* Removed `classMethods` and `instanceMethods` options from `sequelize.define`. Sequelize models
are now ES6 classes. You can set class / instance level methods like this
**Old**
```js
const Model = sequelize.define('Model', {
...
}, {
classMethods: {
associate: function (model) {...}
},
instanceMethods: {
someMethod: function () { ...}
}
});
```
**New**
```js
const Model = sequelize.define('Model', {
...
});
// Class Method
Model.associate = function (models) {
...associate the models
};
// Instance Method
Model.prototype.someMethod = function () {..}
```
* `options.order` now only accepts values with type of array or Sequelize method. Support for string values (ie `{order: 'name DESC'}`) has been deprecated.
* With `BelongsToMany` relationships `add/set/create` setters now set through attributes by passing them as `options.through` (previously second argument was used as through attributes, now it's considered options with `through` being a sub option)
* Raw options for where, order and group like `where: { $raw: '..', order: [{ raw: '..' }], group: [{ raw: '..' }] }` have been removed to prevent SQL injection attacks.
**Old**
```js
user.addProject(project, { status: 'started' });
```
**New**
```js
user.addProject(project, { through: { status: 'started' } });
```
### Data Types
* (MySQL/Postgres) `BIGINT` now returned as string.
* (MySQL/Postgres) `DECIMAL` and `NEWDECIMAL` types now returned as string.
* (MSSQL) `DataTypes.DATE` now uses `DATETIMEOFFSET` instead of `DATETIME2` sql datatype in case of MSSQL to record timezone. To migrate existing `DATETIME2` columns into `DATETIMEOFFSET`, see [#7201](https://github.com/sequelize/sequelize/pull/7201#issuecomment-278899803).
* `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
### Transactions / CLS
* Removed `autocommit: true` default, set this option explicitly to have transactions auto commit.
* Removed default `REPEATABLE_READ` transaction isolation. The isolation level now defaults to that of the database. Explicitly pass the required isolation level when initiating the transaction.
* The CLS patch does not affect global bluebird promise. Transaction will not automatically get passed to methods when used with `Promise.all` and other bluebird methods. Explicitly patch your bluebird instance to get CLS to work with bluebird methods.
```bash
$ npm install --save cls-bluebird
```
```js
const Sequelize = require('sequelize');
const Promise = require('bluebird');
const clsBluebird = require('cls-bluebird');
const cls = require('continuation-local-storage');
const ns = cls.createNamespace('transaction-namespace');
clsBluebird(ns, Promise);
Sequelize.useCLS(ns);
```
### Raw Queries
* Sequelize now supports bind parameters for all dialects. In v3 `bind` option would fallback to `replacements` if dialect didn't supported binding. This could be a breaking change for MySQL / MSSQL where now queries will actually use bind parameters instead of replacements fallback.
### Others
* `Sequelize.Validator` is now an independent copy of `validator` library.
* `Model.validate` instance method now runs validation hooks by default. Previously you needed to pass `{ hooks: true }`. You can override this behavior by passing `{ hooks: false }`.
* The resulting promise from the `Model.validate` instance method will be rejected when validation fails. It will fulfill when validation succeeds.
* `Sequelize.Utils` is not longer part of the public API, use it at your own risk.
* `Hooks` should return Promises now. Callbacks are deprecated.
* Getters wont run with `instance.get({ raw: true })`, use `instance.get({ plain: true })`
* `required` inside include does not propagate up the include chain.
To get v3 compatible results you'll need to either set `required` on the containing include.
**Old**
```js
user.findOne({
include: {
model: project,
include: {
model: task,
required: true
}
}
});
```
**New**
```js
User.findOne({
include: {
model: Project,
required: true,
include: {
model: Task,
required: true
}
}
});
User.findOne({
include: {
model: Project,
required: true,
include: {
model: Task,
where: { type: 'important' } //where cause required to default to true
}
}
});
```
Optionally you can add a `beforeFind` hook to get v3 compatible behavior -
```js
function propagateRequired(modelDescriptor) {
let include = modelDescriptor.include;
if (!include) return false;
if (!Array.isArray(include)) include = [include];
return include.reduce((isRequired, descriptor) => {
const hasRequiredChild = propagateRequired(descriptor);
if ((descriptor.where || hasRequiredChild) && descriptor.required === undefined) {
descriptor.required = true;
}
return descriptor.required || isRequired;
}, false);
}
const sequelize = new Sequelize(..., {
...,
define: {
hooks: {
beforeFind: propagateRequired
}
}
});
```
......@@ -12,7 +12,7 @@ Sequelize v5 will only support Node 6 and up [#9015](https://github.com/sequeliz
With v4 you started to get a deprecation warning `String based operators are now deprecated`. Also concept of operators was introduced. These operators are Symbols which prevent hash injection attacks.
http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-security
http://docs.sequelizejs.com/manual/querying.html#operators-security
**With v5**
......@@ -181,7 +181,7 @@ Model.findAll({
#### MSSQL
- Sequelize now works with `tedious@6.0.0`, this means old `dialectOptions` has to be updated to match their new format. Please refer to tedious [documentation](http://tediousjs.github.io/tedious/api-connection.html#function_newConnection). An example of new `dialectOptions` is given below
- Sequelize now works with `tedious >= 6.0.0`. Old `dialectOptions` has to be updated to match their new format. Please refer to tedious [documentation](http://tediousjs.github.io/tedious/api-connection.html#function_newConnection). An example of new `dialectOptions` is given below
```json
dialectOptions: {
......@@ -213,6 +213,44 @@ dialectOptions: {
## Changelog
### 5.0.0-beta.17
- fix(build): default null for multiple primary keys
- fix(util): improve performance of classToInvokable [#10534](https://github.com/sequelize/sequelize/pull/10534)
- fix(model/update): propagate paranoid to individualHooks query [#10369](https://github.com/sequelize/sequelize/pull/10369)
- fix(association): use minimal select for hasAssociation [#10529](https://github.com/sequelize/sequelize/pull/10529)
- fix(query-interface): reject with error for describeTable [#10528](https://github.com/sequelize/sequelize/pull/10528)
- fix(model): throw for invalid include type [#10527](https://github.com/sequelize/sequelize/pull/10527)
- fix(types): additional options for db.query and add missing retry [#10512](https://github.com/sequelize/sequelize/pull/10512)
- fix(query): don't prepare options & sql for every retry [#10498](https://github.com/sequelize/sequelize/pull/10498)
- feat: expose Sequelize.BaseError
- feat: upgrade to tedious@6.0.0 [#10494](https://github.com/sequelize/sequelize/pull/10494)
- feat(sqlite/query-generator): support restart identity for truncate-table [#10522](https://github.com/sequelize/sequelize/pull/10522)
- feat(data-types): handle numbers passed as objects [#10492](https://github.com/sequelize/sequelize/pull/10492)
- feat(types): enabled string association [#10481](https://github.com/sequelize/sequelize/pull/10481)
- feat(postgres): allow customizing client_min_messages [#10448](https://github.com/sequelize/sequelize/pull/10448)
- refactor(data-types): move to classes [#10495](https://github.com/sequelize/sequelize/pull/10495)
- docs(legacy): fix N:M example [#10509](https://github.com/sequelize/sequelize/pull/10509)
- docs(migrations): use migrationStorageTableSchema [#10417](https://github.com/sequelize/sequelize/pull/10417)
- docs(hooks): add documentation for connection hooks [#10410](https://github.com/sequelize/sequelize/pull/10410)
- docs(addIndex): concurrently option [#10409](https://github.com/sequelize/sequelize/pull/10409)
- docs(model): fix typo [#10405](https://github.com/sequelize/sequelize/pull/10405)
- docs(usage): fix broken link on Basic Usage [#10381](https://github.com/sequelize/sequelize/pull/10381)
- docs(package.json): add homepage [#10372](https://github.com/sequelize/sequelize/pull/10372)
### 5.0.0-beta.16
- feat: add typescript typings [#10287](https://github.com/sequelize/sequelize/pull/10117)
- fix(mysql): match with newlines in error message [#10320](https://github.com/sequelize/sequelize/pull/10320)
- fix(update): skips update when nothing to update [#10248](https://github.com/sequelize/sequelize/pull/10248)
- fix(utils): flattenObject for null values [#10293](https://github.com/sequelize/sequelize/pull/10293)
- fix(instance-validator): don't skip custom validators on null [#9143](https://github.com/sequelize/sequelize/pull/9143)
- docs(transaction): after save example [#10280](https://github.com/sequelize/sequelize/pull/10280)
- docs(query-generator): typo [#10277](https://github.com/sequelize/sequelize/pull/10277)
- refactor(errors): restructure [#10355](https://github.com/sequelize/sequelize/pull/10355)
- refactor(scope): documentation #9087 [#10312](https://github.com/sequelize/sequelize/pull/10312)
- refactor: cleanup association and spread use [#10276](https://github.com/sequelize/sequelize/pull/10276)
### 5.0.0-beta.16
- feat: add typescript typings [#10287](https://github.com/sequelize/sequelize/pull/10117)
......
......@@ -350,8 +350,8 @@ sequelize.query('select 1 as `foo.bar.baz`').then(rows => {
[0]: /manual/installation/usage.html#options
[1]: /manual/tutorial/models-definition.html#configuration
[1]: /manual/models-definition.html#configuration
[2]: /class/lib/sequelize.js~Sequelize.html
[3]: /manual/tutorial/transactions.html
[3]: /manual/transactions.html
[4]: /variable/index.html#static-variable-QueryTypes
[5]: /class/lib/sequelize.js~Sequelize.html#instance-method-query
......@@ -242,7 +242,7 @@ class Sequelize {
this.dialect.QueryGenerator.typeValidation = options.typeValidation;
if (_.isPlainObject(this.options.operatorsAliases)) {
logger.deprecate('String based operators are deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators');
logger.deprecate('String based operators are deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/querying.html#operators');
this.dialect.QueryGenerator.setOperatorsAliases(this.options.operatorsAliases);
} else if (typeof this.options.operatorsAliases === 'boolean') {
logger.warn('A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!