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

Commit f9595392 by Jan Aagaard Meier Committed by GitHub

Merge pull request #6226 from sequelize/doclets

Update jsdocs for doclets
2 parents 00bf32a3 f48758d6
dir: lib
packageJson: package.json
articles:
- Getting started: docs/articles/getting-started.md
branches:
- master
- doclets
...@@ -34,7 +34,10 @@ const HasOne = require('./has-one'); ...@@ -34,7 +34,10 @@ const HasOne = require('./has-one');
* *
* In the API reference below, replace `Assocation(s)` with the actual name of your association, e.g. for `User.belongsToMany(Project)` the getter will be `user.getProjects()`. * In the API reference below, replace `Assocation(s)` with the actual name of your association, e.g. for `User.belongsToMany(Project)` the getter will be `user.getProjects()`.
* *
* @mixin BelongsToMany * @class BelongsToMany
* @memberof Associations
*
* @see {@link Model.belongsToMany}
*/ */
class BelongsToMany extends Association { class BelongsToMany extends Association {
constructor(source, target, options) { constructor(source, target, options) {
...@@ -203,39 +206,47 @@ class BelongsToMany extends Association { ...@@ -203,39 +206,47 @@ class BelongsToMany extends Association {
* @param {Object} [options.where] An optional where clause to limit the associated models * @param {Object} [options.where] An optional where clause to limit the associated models
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false * @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @param {String} [options.schema] Apply a schema on the related model * @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findAll} for a full explanation of options * @see {@link Model#findAll} for a full explanation of options
* @return {Promise<Array<Instance>>} * @return {Promise<Array<Model>>}
* @method getAssociations * @method getAssociations
* @memberof Associations.BelongsToMany
* @instance
*/ */
get: 'get' + plural, get: 'get' + plural,
/** /**
* Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated. * Set the associated models by passing an array of instances or their primary keys. Everything that it not in the passed array will be un-associated.
* *
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. * @param {Array<Model|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table * @param {Object} [options] Options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table
* @param {Object} [options.validate] Run validation for the join model * @param {Object} [options.validate] Run validation for the join model
* @return {Promise} * @return {Promise}
* @method setAssociations * @method setAssociations
* @memberof Associations.BelongsToMany
* @instance
*/ */
set: 'set' + plural, set: 'set' + plural,
/** /**
* Associate several persisted instances with this. * Associate several persisted instances with this.
* *
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. * @param {Array<Model|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this.
* @param {Object} [options] Options passed to `through.findAll`, `bulkCreate` and `update`. Can also hold additional attributes for the join table. * @param {Object} [options] Options passed to `through.findAll`, `bulkCreate` and `update`. Can also hold additional attributes for the join table.
* @param {Object} [options.validate] Run validation for the join model. * @param {Object} [options.validate] Run validation for the join model.
* @return {Promise} * @return {Promise}
* @method addAssociations * @method addAssociations
* @memberof Associations.BelongsToMany
* @instance
*/ */
addMultiple: 'add' + plural, addMultiple: 'add' + plural,
/** /**
* Associate a persisted instance with this. * Associate a persisted instance with this.
* *
* @param {Instance|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this. * @param {Model|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this.
* @param {Object} [options] Options passed to `through.findAll`, `bulkCreate` and `update`. Can also hold additional attributes for the join table. * @param {Object} [options] Options passed to `through.findAll`, `bulkCreate` and `update`. Can also hold additional attributes for the join table.
* @param {Object} [options.validate] Run validation for the join model. * @param {Object} [options.validate] Run validation for the join model.
* @return {Promise} * @return {Promise}
* @method addAssociation * @method addAssociation
* @memberof Associations.BelongsToMany
* @instance
*/ */
add: 'add' + singular, add: 'add' + singular,
/** /**
...@@ -245,42 +256,52 @@ class BelongsToMany extends Association { ...@@ -245,42 +256,52 @@ class BelongsToMany extends Association {
* @param {Object} [options] Options passed to create and add. Can also hold additional attributes for the join table * @param {Object} [options] Options passed to create and add. Can also hold additional attributes for the join table
* @return {Promise} * @return {Promise}
* @method createAssociation * @method createAssociation
* @memberof Associations.BelongsToMany
* @instance
*/ */
create: 'create' + singular, create: 'create' + singular,
/** /**
* Un-associate the instance. * Un-associate the instance.
* *
* @param {Instance|String|Number} [oldAssociated] Can be an Instance or its primary key * @param {Model|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `through.destroy` * @param {Object} [options] Options passed to `through.destroy`
* @return {Promise} * @return {Promise}
* @method removeAssociation * @method removeAssociation
* @memberof Associations.BelongsToMany
* @instance
*/ */
remove: 'remove' + singular, remove: 'remove' + singular,
/** /**
* Un-associate several instances. * Un-associate several instances.
* *
* @param {Array<Instance|String|Number>} [oldAssociated] Can be an array of instances or their primary keys * @param {Array<Model|String|Number>} [oldAssociated] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to `through.destroy` * @param {Object} [options] Options passed to `through.destroy`
* @return {Promise} * @return {Promise}
* @method removeAssociations * @method removeAssociations
* @memberof Associations.BelongsToMany
* @instance
*/ */
removeMultiple: 'remove' + plural, removeMultiple: 'remove' + plural,
/** /**
* Check if an instance is associated with this. * Check if an instance is associated with this.
* *
* @param {Instance|String|Number} [instance] Can be an Instance or its primary key * @param {Model|String|Number} [instance] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations * @param {Object} [options] Options passed to getAssociations
* @return {Promise} * @return {Promise}
* @method hasAssociation * @method hasAssociation
* @memberof Associations.BelongsToMany
* @instance
*/ */
hasSingle: 'has' + singular, hasSingle: 'has' + singular,
/** /**
* Check if all instances are associated with this. * Check if all instances are associated with this.
* *
* @param {Array<Instance|String|Number>} [instances] Can be an array of instances or their primary keys * @param {Array<Model|String|Number>} [instances] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to getAssociations * @param {Object} [options] Options passed to getAssociations
* @return {Promise} * @return {Promise}
* @method hasAssociations * @method hasAssociations
* @memberof Associations.BelongsToMany
* @instance
*/ */
hasAll: 'has' + plural, hasAll: 'has' + plural,
/** /**
...@@ -289,8 +310,10 @@ class BelongsToMany extends Association { ...@@ -289,8 +310,10 @@ class BelongsToMany extends Association {
* @param {Object} [options] * @param {Object} [options]
* @param {Object} [options.where] An optional where clause to limit the associated models * @param {Object} [options.where] An optional where clause to limit the associated models
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false * @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @return {Promise<Int>} * @return {Promise<Integer>}
* @method countAssociations * @method countAssociations
* @memberof Associations.BelongsToMany
* @instance
*/ */
count: 'count' + plural count: 'count' + plural
}; };
......
...@@ -11,7 +11,10 @@ const Association = require('./base'); ...@@ -11,7 +11,10 @@ const Association = require('./base');
* *
* In the API reference below, replace `Assocation` with the actual name of your association, e.g. for `User.belongsTo(Project)` the getter will be `user.getProject()`. * In the API reference below, replace `Assocation` with the actual name of your association, e.g. for `User.belongsTo(Project)` the getter will be `user.getProject()`.
* *
* @mixin BelongsTo * @class BelongsTo
* @memberof Associations
*
* @see {@link Model.belongsTo}
*/ */
class BelongsTo extends Association { class BelongsTo extends Association {
constructor(source, target, options) { constructor(source, target, options) {
...@@ -78,19 +81,21 @@ class BelongsTo extends Association { ...@@ -78,19 +81,21 @@ class BelongsTo extends Association {
* @param {Object} [options] * @param {Object} [options]
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false. * @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false.
* @param {String} [options.schema] Apply a schema on the related model * @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findOne} for a full explanation of options * @see {@link Model.findOne} for a full explanation of options
* @return {Promise<Instance>} * @return {Promise<Model>}
* @method getAssociation * @method getAssociation
* @memberof Associations.BelongsTo
*/ */
get: 'get' + singular, get: 'get' + singular,
/** /**
* Set the associated model. * Set the associated model.
* *
* @param {Instance|String|Number} [newAssociation] An persisted instance or the primary key of an instance to associate with this. Pass `null` or `undefined` to remove the association. * @param {Model|String|Number} [newAssociation] An persisted instance or the primary key of an instance to associate with this. Pass `null` or `undefined` to remove the association.
* @param {Object} [options] Options passed to `this.save` * @param {Object} [options] Options passed to `this.save`
* @param {Boolean} [options.save=true] Skip saving this after setting the foreign key if false. * @param {Boolean} [options.save=true] Skip saving this after setting the foreign key if false.
* @return {Promise} * @return {Promise}
* @method setAssociation * @method setAssociation
* @memberof Associations.BelongsTo
*/ */
set: 'set' + singular, set: 'set' + singular,
/** /**
...@@ -98,9 +103,10 @@ class BelongsTo extends Association { ...@@ -98,9 +103,10 @@ class BelongsTo extends Association {
* *
* @param {Object} [values] * @param {Object} [values]
* @param {Object} [options] Options passed to `target.create` and setAssociation. * @param {Object} [options] Options passed to `target.create` and setAssociation.
* @see {Model#create} for a full explanation of options * @see {@link Model#create} for a full explanation of options
* @return {Promise} * @return {Promise}
* @method createAssociation * @method createAssociation
* @memberof Associations.BelongsTo
*/ */
create: 'create' + singular create: 'create' + singular
}; };
......
...@@ -10,7 +10,10 @@ const Association = require('./base'); ...@@ -10,7 +10,10 @@ const Association = require('./base');
* *
* In the API reference below, replace `Association(s)` with the actual name of your association, e.g. for `User.hasMany(Project)` the getter will be `user.getProjects()`. * In the API reference below, replace `Association(s)` with the actual name of your association, e.g. for `User.hasMany(Project)` the getter will be `user.getProjects()`.
* *
* @mixin HasMany * @class HasMany
* @memberof Associations
*
* @see {@link Model.hasMany}
*/ */
class HasMany extends Association { class HasMany extends Association {
constructor(source, target, options) { constructor(source, target, options) {
...@@ -97,39 +100,43 @@ class HasMany extends Association { ...@@ -97,39 +100,43 @@ class HasMany extends Association {
* @param {Object} [options.where] An optional where clause to limit the associated models * @param {Object} [options.where] An optional where clause to limit the associated models
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false * @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @param {String} [options.schema] Apply a schema on the related model * @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findAll} for a full explanation of options * @see {@link Model#findAll} for a full explanation of options
* @return {Promise<Array<Instance>>} * @return {Promise<Array<Model>>}
* @method getAssociations * @method getAssociations
* @memberof Associations.HasMany
*/ */
get: 'get' + plural, get: 'get' + plural,
/** /**
* Set the associated models by passing an array of persisted instances or their primary keys. Everything that is not in the passed array will be un-associated * Set the associated models by passing an array of persisted instances or their primary keys. Everything that is not in the passed array will be un-associated
* *
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations. * @param {Array<Model|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. Pass `null` or `undefined` to remove all associations.
* @param {Object} [options] Options passed to `target.findAll` and `update`. * @param {Object} [options] Options passed to `target.findAll` and `update`.
* @param {Object} [options.validate] Run validation for the join model * @param {Object} [options.validate] Run validation for the join model
* @return {Promise} * @return {Promise}
* @method setAssociations * @method setAssociations
* @memberof Associations.HasMany
*/ */
set: 'set' + plural, set: 'set' + plural,
/** /**
* Associate several persisted instances with this. * Associate several persisted instances with this.
* *
* @param {Array<Instance|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this. * @param {Array<Model|String|Number>} [newAssociations] An array of persisted instances or primary key of instances to associate with this.
* @param {Object} [options] Options passed to `target.update`. * @param {Object} [options] Options passed to `target.update`.
* @param {Object} [options.validate] Run validation for the join model. * @param {Object} [options.validate] Run validation for the join model.
* @return {Promise} * @return {Promise}
* @method addAssociations * @method addAssociations
* @memberof Associations.HasMany
*/ */
addMultiple: 'add' + plural, addMultiple: 'add' + plural,
/** /**
* Associate a persisted instance with this. * Associate a persisted instance with this.
* *
* @param {Instance|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this. * @param {Model|String|Number} [newAssociation] A persisted instance or primary key of instance to associate with this.
* @param {Object} [options] Options passed to `target.update`. * @param {Object} [options] Options passed to `target.update`.
* @param {Object} [options.validate] Run validation for the join model. * @param {Object} [options.validate] Run validation for the join model.
* @return {Promise} * @return {Promise}
* @method addAssociation * @method addAssociation
* @memberof Associations.HasMany
*/ */
add: 'add' + singular, add: 'add' + singular,
/** /**
...@@ -139,42 +146,47 @@ class HasMany extends Association { ...@@ -139,42 +146,47 @@ class HasMany extends Association {
* @param {Object} [options] Options passed to `target.create`. * @param {Object} [options] Options passed to `target.create`.
* @return {Promise} * @return {Promise}
* @method createAssociation * @method createAssociation
* @memberof Associations.HasMany
*/ */
create: 'create' + singular, create: 'create' + singular,
/** /**
* Un-associate the instance. * Un-associate the instance.
* *
* @param {Instance|String|Number} [oldAssociated] Can be an Instance or its primary key * @param {Model|String|Number} [oldAssociated] Can be an Instance or its primary key
* @param {Object} [options] Options passed to `target.update` * @param {Object} [options] Options passed to `target.update`
* @return {Promise} * @return {Promise}
* @method removeAssociation * @method removeAssociation
* @memberof Associations.HasMany
*/ */
remove: 'remove' + singular, remove: 'remove' + singular,
/** /**
* Un-associate several instances. * Un-associate several instances.
* *
* @param {Array<Instance|String|Number>} [oldAssociatedArray] Can be an array of instances or their primary keys * @param {Array<Model|String|Number>} [oldAssociatedArray] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to `through.destroy` * @param {Object} [options] Options passed to `through.destroy`
* @return {Promise} * @return {Promise}
* @method removeAssociations * @method removeAssociations
* @memberof Associations.HasMany
*/ */
removeMultiple: 'remove' + plural, removeMultiple: 'remove' + plural,
/** /**
* Check if an instance is associated with this. * Check if an instance is associated with this.
* *
* @param {Instance|String|Number} [instance] Can be an Instance or its primary key * @param {Model|String|Number} [instance] Can be an Instance or its primary key
* @param {Object} [options] Options passed to getAssociations * @param {Object} [options] Options passed to getAssociations
* @return {Promise} * @return {Promise}
* @method hasAssociation * @method hasAssociation
* @memberof Associations.HasMany
*/ */
hasSingle: 'has' + singular, hasSingle: 'has' + singular,
/** /**
* Check if all instances are associated with this. * Check if all instances are associated with this.
* *
* @param {Array<Instance|String|Number>} [instances] Can be an array of instances or their primary keys * @param {Array<Model|String|Number>} [instances] Can be an array of instances or their primary keys
* @param {Object} [options] Options passed to getAssociations * @param {Object} [options] Options passed to getAssociations
* @return {Promise} * @return {Promise}
* @method hasAssociations * @method hasAssociations
* @memberof Associations.HasMany
*/ */
hasAll: 'has' + plural, hasAll: 'has' + plural,
/** /**
...@@ -183,8 +195,9 @@ class HasMany extends Association { ...@@ -183,8 +195,9 @@ class HasMany extends Association {
* @param {Object} [options] * @param {Object} [options]
* @param {Object} [options.where] An optional where clause to limit the associated models * @param {Object} [options.where] An optional where clause to limit the associated models
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false * @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @return {Promise<Int>} * @return {Promise<Integer>}
* @method countAssociations * @method countAssociations
* @memberof Associations.HasMany
*/ */
count: 'count' + plural count: 'count' + plural
}; };
......
...@@ -11,7 +11,10 @@ const Association = require('./base'); ...@@ -11,7 +11,10 @@ const Association = require('./base');
* In the API reference below, replace `Association` with the actual name of your association, e.g. for `User.hasOne(Project)` the getter will be `user.getProject()`. * In the API reference below, replace `Association` with the actual name of your association, e.g. for `User.hasOne(Project)` the getter will be `user.getProject()`.
* This is almost the same as `belongsTo` with one exception. The foreign key will be defined on the target model. * This is almost the same as `belongsTo` with one exception. The foreign key will be defined on the target model.
* *
* @mixin HasOne * @class HasOne
* @memberof Associations
*
* @see {@link Model.hasOne}
*/ */
class HasOne extends Association { class HasOne extends Association {
constructor(srcModel, targetModel, options) { constructor(srcModel, targetModel, options) {
...@@ -75,18 +78,20 @@ class HasOne extends Association { ...@@ -75,18 +78,20 @@ class HasOne extends Association {
* @param {Object} [options] * @param {Object} [options]
* @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false * @param {String|Boolean} [options.scope] Apply a scope on the related model, or remove its default scope by passing false
* @param {String} [options.schema] Apply a schema on the related model * @param {String} [options.schema] Apply a schema on the related model
* @see {Model#findOne} for a full explanation of options * @see {@link Model#findOne} for a full explanation of options
* @return {Promise<Instance>} * @return {Promise<Model>}
* @method getAssociation * @method getAssociation
* @memberof Associations.HasOne
*/ */
get: 'get' + singular, get: 'get' + singular,
/** /**
* Set the associated model. * Set the associated model.
* *
* @param {Instance|String|Number} [newAssociation] An persisted instance or the primary key of a persisted instance to associate with this. Pass `null` or `undefined` to remove the association. * @param {Model|String|Number} [newAssociation] An persisted instance or the primary key of a persisted instance to associate with this. Pass `null` or `undefined` to remove the association.
* @param {Object} [options] Options passed to getAssociation and `target.save` * @param {Object} [options] Options passed to getAssociation and `target.save`
* @return {Promise} * @return {Promise}
* @method setAssociation * @method setAssociation
* @memberof Associations.HasOne
*/ */
set: 'set' + singular, set: 'set' + singular,
/** /**
...@@ -94,9 +99,10 @@ class HasOne extends Association { ...@@ -94,9 +99,10 @@ class HasOne extends Association {
* *
* @param {Object} [values] * @param {Object} [values]
* @param {Object} [options] Options passed to `target.create` and setAssociation. * @param {Object} [options] Options passed to `target.create` and setAssociation.
* @see {Model#create} for a full explanation of options * @see {@link Model#create} for a full explanation of options
* @return {Promise} * @return {Promise}
* @method createAssociation * @method createAssociation
* @memberof Associations.HasOne
*/ */
create: 'create' + singular create: 'create' + singular
}; };
......
...@@ -83,7 +83,7 @@ const BelongsTo = require('./belongs-to'); ...@@ -83,7 +83,7 @@ const BelongsTo = require('./belongs-to');
* *
* Note how we also specified `constraints: false` for profile picture. This is because we add a foreign key from user to picture (profilePictureId), and from picture to user (userId). If we were to add foreign keys to both, it would create a cyclic dependency, and sequelize would not know which table to create first, since user depends on picture, and picture depends on user. These kinds of problems are detected by sequelize before the models are synced to the database, and you will get an error along the lines of `Error: Cyclic dependency found. 'users' is dependent of itself`. If you encounter this, you should either disable some constraints, or rethink your associations completely. * Note how we also specified `constraints: false` for profile picture. This is because we add a foreign key from user to picture (profilePictureId), and from picture to user (userId). If we were to add foreign keys to both, it would create a cyclic dependency, and sequelize would not know which table to create first, since user depends on picture, and picture depends on user. These kinds of problems are detected by sequelize before the models are synced to the database, and you will get an error along the lines of `Error: Cyclic dependency found. 'users' is dependent of itself`. If you encounter this, you should either disable some constraints, or rethink your associations completely.
* *
* @mixin Associations * @namespace Associations
* @name Associations * @name Associations
*/ */
const Mixin = { const Mixin = {
...@@ -101,6 +101,8 @@ const Mixin = { ...@@ -101,6 +101,8 @@ const Mixin = {
* @param {string} [options.onDelete='SET&nbsp;NULL|CASCADE'] SET NULL if foreignKey allows nulls, CASCADE if otherwise * @param {string} [options.onDelete='SET&nbsp;NULL|CASCADE'] SET NULL if foreignKey allows nulls, CASCADE if otherwise
* @param {string} [options.onUpdate='CASCADE'] * @param {string} [options.onUpdate='CASCADE']
* @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key. * @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key.
* @returns {Associations.HasMany}
* @memberof Model
*/ */
hasMany(target, options) { // testhint options:none hasMany(target, options) { // testhint options:none
if (!target.prototype || !(target.prototype instanceof this.sequelize.Model)) { if (!target.prototype || !(target.prototype instanceof this.sequelize.Model)) {
...@@ -180,6 +182,8 @@ const Mixin = { ...@@ -180,6 +182,8 @@ const Mixin = {
* @param {string} [options.onDelete='SET&nbsp;NULL|CASCADE'] Cascade if this is a n:m, and set null if it is a 1:m * @param {string} [options.onDelete='SET&nbsp;NULL|CASCADE'] Cascade if this is a n:m, and set null if it is a 1:m
* @param {string} [options.onUpdate='CASCADE'] * @param {string} [options.onUpdate='CASCADE']
* @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key. * @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key.
* @returns {Associations.BelongsToMany}
* @memberof Model
*/ */
belongsToMany(targetModel, options) { // testhint options:none belongsToMany(targetModel, options) { // testhint options:none
if (!targetModel.prototype || !(targetModel.prototype instanceof this.sequelize.Model)) { if (!targetModel.prototype || !(targetModel.prototype instanceof this.sequelize.Model)) {
...@@ -265,6 +269,8 @@ function singleLinked(Type) { ...@@ -265,6 +269,8 @@ function singleLinked(Type) {
* @param {string} [options.onDelete='SET&nbsp;NULL|CASCADE'] SET NULL if foreignKey allows nulls, CASCADE if otherwise * @param {string} [options.onDelete='SET&nbsp;NULL|CASCADE'] SET NULL if foreignKey allows nulls, CASCADE if otherwise
* @param {string} [options.onUpdate='CASCADE'] * @param {string} [options.onUpdate='CASCADE']
* @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key. * @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key.
* @returns {Associations.HasOne}
* @memberof Model
*/ */
Mixin.hasOne = singleLinked(HasOne); Mixin.hasOne = singleLinked(HasOne);
...@@ -283,6 +289,8 @@ Mixin.hasOne = singleLinked(HasOne); ...@@ -283,6 +289,8 @@ Mixin.hasOne = singleLinked(HasOne);
* @param {string} [options.onDelete='SET&nbsp;NULL|NO&nbsp;ACTION'] SET NULL if foreignKey allows nulls, NO ACTION if otherwise * @param {string} [options.onDelete='SET&nbsp;NULL|NO&nbsp;ACTION'] SET NULL if foreignKey allows nulls, NO ACTION if otherwise
* @param {string} [options.onUpdate='CASCADE'] * @param {string} [options.onUpdate='CASCADE']
* @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key. * @param {boolean} [options.constraints=true] Should on update and on delete constraints be enabled on the foreign key.
* @returns {Associations.BelongsTo}
* @memberof Model
*/ */
Mixin.belongsTo = singleLinked(BelongsTo); Mixin.belongsTo = singleLinked(BelongsTo);
......
...@@ -53,7 +53,7 @@ const moment = require('moment'); ...@@ -53,7 +53,7 @@ const moment = require('moment');
* }) * })
* ``` * ```
* *
* @class DataTypes * @namespace DataTypes
*/ */
function ABSTRACT() {} function ABSTRACT() {}
...@@ -82,9 +82,8 @@ ABSTRACT.prototype.stringify = function stringify(value, options) { ...@@ -82,9 +82,8 @@ ABSTRACT.prototype.stringify = function stringify(value, options) {
/** /**
* A variable length string. Default length 255 * A variable length string. Default length 255
* *
* Available properties: `BINARY` * @property BINARY
* * @memberof DataTypes
* @property STRING
*/ */
function STRING(length, binary) { function STRING(length, binary) {
const options = typeof length === 'object' && length || {length, binary}; const options = typeof length === 'object' && length || {length, binary};
...@@ -124,7 +123,7 @@ Object.defineProperty(STRING.prototype, 'BINARY', { ...@@ -124,7 +123,7 @@ Object.defineProperty(STRING.prototype, 'BINARY', {
* *
* Available properties: `BINARY` * Available properties: `BINARY`
* *
* @property CHAR * @memberof DataTypes
*/ */
function CHAR(length, binary) { function CHAR(length, binary) {
const options = typeof length === 'object' && length || {length, binary}; const options = typeof length === 'object' && length || {length, binary};
...@@ -141,7 +140,8 @@ CHAR.prototype.toSql = function toSql() { ...@@ -141,7 +140,8 @@ CHAR.prototype.toSql = function toSql() {
/** /**
* An (un)limited length text column. Available lengths: `tiny`, `medium`, `long` * An (un)limited length text column. Available lengths: `tiny`, `medium`, `long`
* @property TEXT *
* @memberof DataTypes
*/ */
function TEXT(length) { function TEXT(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || {length};
...@@ -228,9 +228,9 @@ Object.defineProperty(NUMBER.prototype, 'ZEROFILL', { ...@@ -228,9 +228,9 @@ Object.defineProperty(NUMBER.prototype, 'ZEROFILL', {
/** /**
* A 32 bit integer. * A 32 bit integer.
* *
* Available properties: `UNSIGNED`, `ZEROFILL` * @property UNSIGNED
* * @property ZEROFILL
* @property INTEGER * @memberof DataTypes
*/ */
function INTEGER(length) { function INTEGER(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || {length};
...@@ -253,9 +253,9 @@ INTEGER.prototype.validate = function validate(value) { ...@@ -253,9 +253,9 @@ INTEGER.prototype.validate = function validate(value) {
* *
* Note: an attribute defined as `BIGINT` will be treated like a `string` due this [feature from node-postgres](https://github.com/brianc/node-postgres/pull/353) to prevent precision loss. To have this attribute as a `number`, this is a possible [workaround](https://github.com/sequelize/sequelize/issues/2383#issuecomment-58006083). * Note: an attribute defined as `BIGINT` will be treated like a `string` due this [feature from node-postgres](https://github.com/brianc/node-postgres/pull/353) to prevent precision loss. To have this attribute as a `number`, this is a possible [workaround](https://github.com/sequelize/sequelize/issues/2383#issuecomment-58006083).
* *
* Available properties: `UNSIGNED`, `ZEROFILL` * @property UNSIGNED
* * @property ZEROFILL
* @property BIGINT * @memberof DataTypes
*/ */
function BIGINT(length) { function BIGINT(length) {
...@@ -277,9 +277,9 @@ BIGINT.prototype.validate = function validate(value) { ...@@ -277,9 +277,9 @@ BIGINT.prototype.validate = function validate(value) {
/** /**
* Floating point number (4-byte precision). Accepts one or two arguments for precision * Floating point number (4-byte precision). Accepts one or two arguments for precision
* *
* Available properties: `UNSIGNED`, `ZEROFILL` * @property UNSIGNED
* * @property ZEROFILL
* @property FLOAT * @memberof DataTypes
*/ */
function FLOAT(length, decimals) { function FLOAT(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals}; const options = typeof length === 'object' && length || {length, decimals};
...@@ -300,9 +300,9 @@ FLOAT.prototype.validate = function validate(value) { ...@@ -300,9 +300,9 @@ FLOAT.prototype.validate = function validate(value) {
/** /**
* Floating point number (4-byte precision). Accepts one or two arguments for precision * Floating point number (4-byte precision). Accepts one or two arguments for precision
* *
* Available properties: `UNSIGNED`, `ZEROFILL` * @property UNSIGNED
* * @property ZEROFILL
* @property REAL * @memberof DataTypes
*/ */
function REAL(length, decimals) { function REAL(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals}; const options = typeof length === 'object' && length || {length, decimals};
...@@ -316,9 +316,9 @@ REAL.prototype.key = REAL.key = 'REAL'; ...@@ -316,9 +316,9 @@ REAL.prototype.key = REAL.key = 'REAL';
/** /**
* Floating point number (8-byte precision). Accepts one or two arguments for precision * Floating point number (8-byte precision). Accepts one or two arguments for precision
* *
* Available properties: `UNSIGNED`, `ZEROFILL` * @property UNSIGNED
* * @property ZEROFILL
* @property DOUBLE * @memberof DataTypes
*/ */
function DOUBLE(length, decimals) { function DOUBLE(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals}; const options = typeof length === 'object' && length || {length, decimals};
...@@ -332,9 +332,9 @@ DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION'; ...@@ -332,9 +332,9 @@ DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION';
/** /**
* Decimal number. Accepts one or two arguments for precision * Decimal number. Accepts one or two arguments for precision
* *
* Available properties: `UNSIGNED`, `ZEROFILL` * @property UNSIGNED
* * @property ZEROFILL
* @property DECIMAL * @memberof DataTypes
*/ */
function DECIMAL(precision, scale) { function DECIMAL(precision, scale) {
const options = typeof precision === 'object' && precision || {precision, scale}; const options = typeof precision === 'object' && precision || {precision, scale};
...@@ -376,7 +376,8 @@ for (const floating of [FLOAT, DOUBLE, REAL]) { ...@@ -376,7 +376,8 @@ for (const floating of [FLOAT, DOUBLE, REAL]) {
/** /**
* A boolean / tinyint column, depending on dialect * A boolean / tinyint column, depending on dialect
* @property BOOLEAN *
* @memberof DataTypes
*/ */
function BOOLEAN() { function BOOLEAN() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN(); if (!(this instanceof BOOLEAN)) return new BOOLEAN();
...@@ -397,7 +398,8 @@ BOOLEAN.prototype.validate = function validate(value) { ...@@ -397,7 +398,8 @@ BOOLEAN.prototype.validate = function validate(value) {
/** /**
* A time column * A time column
* @property TIME *
* @memberof DataTypes
*/ */
function TIME() { function TIME() {
...@@ -412,7 +414,8 @@ TIME.prototype.toSql = function toSql() { ...@@ -412,7 +414,8 @@ TIME.prototype.toSql = function toSql() {
/** /**
* A datetime column * A datetime column
* @property DATE *
* @memberof DataTypes
*/ */
function DATE(length) { function DATE(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || {length};
...@@ -459,7 +462,8 @@ DATE.prototype._stringify = function _stringify(date, options) { ...@@ -459,7 +462,8 @@ DATE.prototype._stringify = function _stringify(date, options) {
/** /**
* A date only column * A date only column
* @property DATEONLY *
* @memberof DataTypes
*/ */
function DATEONLY() { function DATEONLY() {
...@@ -474,7 +478,8 @@ DATEONLY.prototype.toSql = function() { ...@@ -474,7 +478,8 @@ DATEONLY.prototype.toSql = function() {
/** /**
* A key / value column. Only available in postgres. * A key / value column. Only available in postgres.
* @property HSTORE *
* @memberof DataTypes
*/ */
function HSTORE() { function HSTORE() {
...@@ -493,7 +498,9 @@ HSTORE.prototype.validate = function validate(value) { ...@@ -493,7 +498,9 @@ HSTORE.prototype.validate = function validate(value) {
/** /**
* A JSON string column. Only available in postgres. * A JSON string column. Only available in postgres.
* @property JSON *
* @function JSON
* @memberof DataTypes
*/ */
function JSONTYPE() { function JSONTYPE() {
if (!(this instanceof JSONTYPE)) return new JSONTYPE(); if (!(this instanceof JSONTYPE)) return new JSONTYPE();
...@@ -511,7 +518,8 @@ JSONTYPE.prototype._stringify = function _stringify(value, options) { ...@@ -511,7 +518,8 @@ JSONTYPE.prototype._stringify = function _stringify(value, options) {
/** /**
* A pre-processed JSON data column. Only available in postgres. * A pre-processed JSON data column. Only available in postgres.
* @property JSONB *
* @memberof DataTypes
*/ */
function JSONB() { function JSONB() {
if (!(this instanceof JSONB)) return new JSONB(); if (!(this instanceof JSONB)) return new JSONB();
...@@ -523,7 +531,8 @@ JSONB.prototype.key = JSONB.key = 'JSONB'; ...@@ -523,7 +531,8 @@ JSONB.prototype.key = JSONB.key = 'JSONB';
/** /**
* A default value of the current timestamp * A default value of the current timestamp
* @property NOW *
* @memberof DataTypes
*/ */
function NOW() { function NOW() {
if (!(this instanceof NOW)) return new NOW(); if (!(this instanceof NOW)) return new NOW();
...@@ -535,7 +544,7 @@ NOW.prototype.key = NOW.key = 'NOW'; ...@@ -535,7 +544,7 @@ NOW.prototype.key = NOW.key = 'NOW';
/** /**
* Binary storage. Available lengths: `tiny`, `medium`, `long` * Binary storage. Available lengths: `tiny`, `medium`, `long`
* *
* @property BLOB * @memberof DataTypes
*/ */
function BLOB(length) { function BLOB(length) {
const options = typeof length === 'object' && length || {length}; const options = typeof length === 'object' && length || {length};
...@@ -588,7 +597,8 @@ BLOB.prototype._hexify = function _hexify(hex) { ...@@ -588,7 +597,8 @@ BLOB.prototype._hexify = function _hexify(hex) {
* Range types are data types representing a range of values of some element type (called the range's subtype). * Range types are data types representing a range of values of some element type (called the range's subtype).
* Only available in postgres. * Only available in postgres.
* See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres documentation} for more details * See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres documentation} for more details
* @property RANGE *
* @memberof DataTypes
*/ */
function RANGE(subtype) { function RANGE(subtype) {
...@@ -651,7 +661,8 @@ RANGE.prototype.validate = function validate(value) { ...@@ -651,7 +661,8 @@ RANGE.prototype.validate = function validate(value) {
/** /**
* A column storing a unique universal identifier. Use with `UUIDV1` or `UUIDV4` for default values. * A column storing a unique universal identifier. Use with `UUIDV1` or `UUIDV4` for default values.
* @property UUID *
* @memberof DataTypes
*/ */
function UUID() { function UUID() {
if (!(this instanceof UUID)) return new UUID(); if (!(this instanceof UUID)) return new UUID();
...@@ -669,7 +680,8 @@ UUID.prototype.validate = function validate(value, options) { ...@@ -669,7 +680,8 @@ UUID.prototype.validate = function validate(value, options) {
/** /**
* A default unique universal identifier generated following the UUID v1 standard * A default unique universal identifier generated following the UUID v1 standard
* @property UUIDV1 *
* @memberof DataTypes
*/ */
function UUIDV1() { function UUIDV1() {
...@@ -688,7 +700,8 @@ UUIDV1.prototype.validate = function validate(value, options) { ...@@ -688,7 +700,8 @@ UUIDV1.prototype.validate = function validate(value, options) {
/** /**
* A default unique universal identifier generated following the UUID v4 standard * A default unique universal identifier generated following the UUID v4 standard
* @property UUIDV4 *
* @memberof DataTypes
*/ */
function UUIDV4() { function UUIDV4() {
...@@ -744,8 +757,7 @@ UUIDV4.prototype.validate = function validate(value, options) { ...@@ -744,8 +757,7 @@ UUIDV4.prototype.validate = function validate(value, options) {
* } * }
* ``` * ```
* *
* @property VIRTUAL * @memberof DataTypes
* @alias NONE
*/ */
function VIRTUAL(ReturnType, fields) { function VIRTUAL(ReturnType, fields) {
if (!(this instanceof VIRTUAL)) return new VIRTUAL(ReturnType, fields); if (!(this instanceof VIRTUAL)) return new VIRTUAL(ReturnType, fields);
...@@ -761,7 +773,7 @@ VIRTUAL.prototype.key = VIRTUAL.key = 'VIRTUAL'; ...@@ -761,7 +773,7 @@ VIRTUAL.prototype.key = VIRTUAL.key = 'VIRTUAL';
/** /**
* An enumeration. `DataTypes.ENUM('value', 'another value')`. * An enumeration. `DataTypes.ENUM('value', 'another value')`.
* *
* @property ENUM * @memberof DataTypes
*/ */
function ENUM(value) { function ENUM(value) {
const options = typeof value === 'object' && !Array.isArray(value) && value || { const options = typeof value === 'object' && !Array.isArray(value) && value || {
...@@ -786,7 +798,8 @@ ENUM.prototype.validate = function validate(value) { ...@@ -786,7 +798,8 @@ ENUM.prototype.validate = function validate(value) {
/** /**
* An array of `type`, e.g. `DataTypes.ARRAY(DataTypes.DECIMAL)`. Only available in postgres. * An array of `type`, e.g. `DataTypes.ARRAY(DataTypes.DECIMAL)`. Only available in postgres.
* @property ARRAY *
* @memberof DataTypes
*/ */
function ARRAY(type) { function ARRAY(type) {
const options = _.isPlainObject(type) ? type : {type}; const options = _.isPlainObject(type) ? type : {type};
...@@ -866,7 +879,7 @@ const helpers = { ...@@ -866,7 +879,7 @@ const helpers = {
* }); * });
* ``` * ```
* *
* @property GEOMETRY * @memberof DataTypes
*/ */
function GEOMETRY(type, srid) { function GEOMETRY(type, srid) {
...@@ -889,7 +902,8 @@ GEOMETRY.prototype._stringify = function _stringify(value, options) { ...@@ -889,7 +902,8 @@ GEOMETRY.prototype._stringify = function _stringify(value, options) {
/** /**
* A geography datatype represents two dimensional spacial objects in an elliptic coord system. * A geography datatype represents two dimensional spacial objects in an elliptic coord system.
* @property GEOGRAPHY *
* @memberof DataTypes
*/ */
function GEOGRAPHY(type, srid) { function GEOGRAPHY(type, srid) {
......
...@@ -34,7 +34,14 @@ var util = require('util'); ...@@ -34,7 +34,14 @@ var util = require('util');
* }); * });
* ``` * ```
* *
* @return {object} * @namespace Deferrable
* @memberof Sequelize
*
* @property INITIALLY_DEFERRED Defer constraints checks to the end of transactions.
* @property INITIALLY_IMMEDIATE Trigger the constraint checks immediately
* @property NOT Set the constraints to not deferred. This is the default in PostgreSQL and it make it impossible to dynamically defer the constraints within a transaction.
* @property SET_DEFERRED
* @property SET_IMMEDIATE
*/ */
var Deferrable = module.exports = { var Deferrable = module.exports = {
INITIALLY_DEFERRED, INITIALLY_DEFERRED,
...@@ -50,12 +57,6 @@ ABSTRACT.prototype.toString = function() { ...@@ -50,12 +57,6 @@ ABSTRACT.prototype.toString = function() {
return this.toSql.apply(this, arguments); return this.toSql.apply(this, arguments);
}; };
/**
* A property that will defer constraints checks to the end of transactions.
*
* @property INITIALLY_DEFERRED
*/
function INITIALLY_DEFERRED() { function INITIALLY_DEFERRED() {
if (!(this instanceof INITIALLY_DEFERRED)) { if (!(this instanceof INITIALLY_DEFERRED)) {
return new INITIALLY_DEFERRED(); return new INITIALLY_DEFERRED();
...@@ -67,12 +68,6 @@ INITIALLY_DEFERRED.prototype.toSql = function() { ...@@ -67,12 +68,6 @@ INITIALLY_DEFERRED.prototype.toSql = function() {
return 'DEFERRABLE INITIALLY DEFERRED'; return 'DEFERRABLE INITIALLY DEFERRED';
}; };
/**
* A property that will trigger the constraint checks immediately
*
* @property INITIALLY_IMMEDIATE
*/
function INITIALLY_IMMEDIATE() { function INITIALLY_IMMEDIATE() {
if (!(this instanceof INITIALLY_IMMEDIATE)) { if (!(this instanceof INITIALLY_IMMEDIATE)) {
return new INITIALLY_IMMEDIATE(); return new INITIALLY_IMMEDIATE();
...@@ -84,14 +79,6 @@ INITIALLY_IMMEDIATE.prototype.toSql = function() { ...@@ -84,14 +79,6 @@ INITIALLY_IMMEDIATE.prototype.toSql = function() {
return 'DEFERRABLE INITIALLY IMMEDIATE'; return 'DEFERRABLE INITIALLY IMMEDIATE';
}; };
/**
* A property that will set the constraints to not deferred. This is
* the default in PostgreSQL and it make it impossible to dynamically
* defer the constraints within a transaction.
*
* @property NOT
*/
function NOT() { function NOT() {
if (!(this instanceof NOT)) { if (!(this instanceof NOT)) {
return new NOT(); return new NOT();
...@@ -103,14 +90,6 @@ NOT.prototype.toSql = function() { ...@@ -103,14 +90,6 @@ NOT.prototype.toSql = function() {
return 'NOT DEFERRABLE'; return 'NOT DEFERRABLE';
}; };
/**
* A property that will trigger an additional query at the beginning of a
* transaction which sets the constraints to deferred.
*
* @param {Array} constraints An array of constraint names. Will defer all constraints by default.
* @property SET_DEFERRED
*/
function SET_DEFERRED(constraints) { function SET_DEFERRED(constraints) {
if (!(this instanceof SET_DEFERRED)) { if (!(this instanceof SET_DEFERRED)) {
return new SET_DEFERRED(constraints); return new SET_DEFERRED(constraints);
...@@ -124,14 +103,6 @@ SET_DEFERRED.prototype.toSql = function(queryGenerator) { ...@@ -124,14 +103,6 @@ SET_DEFERRED.prototype.toSql = function(queryGenerator) {
return queryGenerator.setDeferredQuery(this.constraints); return queryGenerator.setDeferredQuery(this.constraints);
}; };
/**
* A property that will trigger an additional query at the beginning of a
* transaction which sets the constraints to immediately.
*
* @param {Array} constraints An array of constraint names. Will defer all constraints by default.
* @property SET_IMMEDIATE
*/
function SET_IMMEDIATE(constraints) { function SET_IMMEDIATE(constraints) {
if (!(this instanceof SET_IMMEDIATE)) { if (!(this instanceof SET_IMMEDIATE)) {
return new SET_IMMEDIATE(constraints); return new SET_IMMEDIATE(constraints);
......
...@@ -13,11 +13,6 @@ const HasMany = require('../../associations/has-many'); ...@@ -13,11 +13,6 @@ const HasMany = require('../../associations/has-many');
const uuid = require('node-uuid'); const uuid = require('node-uuid');
const semver = require('semver'); const semver = require('semver');
/* istanbul ignore next */
function throwMethodUndefined(methodName) {
throw new Error('The method "' + methodName + '" is not defined! Please add it to your sql dialect.');
}
const QueryGenerator = { const QueryGenerator = {
options: {}, options: {},
...@@ -48,33 +43,10 @@ const QueryGenerator = { ...@@ -48,33 +43,10 @@ const QueryGenerator = {
}; };
}, },
/*
Returns a query for dropping a schema
*/
dropSchema(tableName, options) { dropSchema(tableName, options) {
return this.dropTableQuery(tableName, options); return this.dropTableQuery(tableName, options);
}, },
/*
Returns a query for creating a table.
Parameters:
- tableName: Name of the new table.
- attributes: An object with containing attribute-attributeType-pairs.
Attributes should have the format:
{attributeName: type, attr2: type2}
--> e.g. {title: 'VARCHAR(255)'}
- options: An object with options.
Defaults: { engine: 'InnoDB', charset: null }
*/
/* istanbul ignore next */
createTableQuery(tableName, attributes, options) {
throwMethodUndefined('createTableQuery');
},
versionQuery(tableName, attributes, options) {
throwMethodUndefined('versionQuery');
},
describeTableQuery(tableName, schema, schemaDelimiter) { describeTableQuery(tableName, schema, schemaDelimiter) {
const table = this.quoteTable( const table = this.quoteTable(
this.addSchema({ this.addSchema({
...@@ -87,90 +59,19 @@ const QueryGenerator = { ...@@ -87,90 +59,19 @@ const QueryGenerator = {
return 'DESCRIBE ' + table + ';'; return 'DESCRIBE ' + table + ';';
}, },
/*
Returns a query for dropping a table.
*/
dropTableQuery(tableName, options) { dropTableQuery(tableName, options) {
options = options || {}; options = options || {};
return `DROP TABLE IF EXISTS ${this.quoteTable(tableName)};`; return `DROP TABLE IF EXISTS ${this.quoteTable(tableName)};`;
}, },
/*
Returns a rename table query.
Parameters:
- originalTableName: Name of the table before execution.
- futureTableName: Name of the table after execution.
*/
renameTableQuery(before, after) { renameTableQuery(before, after) {
return `ALTER TABLE ${this.quoteTable(before)} RENAME TO ${this.quoteTable(after)};`; return `ALTER TABLE ${this.quoteTable(before)} RENAME TO ${this.quoteTable(after)};`;
}, },
/* /*
Returns a query, which gets all available table names in the database.
*/
/* istanbul ignore next */
showTablesQuery() {
throwMethodUndefined('showTablesQuery');
},
/*
Returns a query, which adds an attribute to an existing table.
Parameters:
- tableName: Name of the existing table.
- attributes: A hash with attribute-attributeOptions-pairs.
- key: attributeName
- value: A hash with attribute specific options:
- type: DataType
- defaultValue: A String with the default value
- allowNull: Boolean
*/
/* istanbul ignore next */
addColumnQuery(tableName, attributes) {
throwMethodUndefined('addColumnQuery');
},
/*
Returns a query, which removes an attribute from an existing table.
Parameters:
- tableName: Name of the existing table
- attributeName: Name of the obsolete attribute.
*/
/* istanbul ignore next */
removeColumnQuery(tableName, attributeName) {
throwMethodUndefined('removeColumnQuery');
},
/*
Returns a query, which modifies an existing attribute from a table.
Parameters:
- tableName: Name of the existing table.
- attributes: A hash with attribute-attributeOptions-pairs.
- key: attributeName
- value: A hash with attribute specific options:
- type: DataType
- defaultValue: A String with the default value
- allowNull: Boolean
*/
/* istanbul ignore next */
changeColumnQuery(tableName, attributes) {
throwMethodUndefined('changeColumnQuery');
},
/*
Returns a query, which renames an existing attribute.
Parameters:
- tableName: Name of an existing table.
- attrNameBefore: The name of the attribute, which shall be renamed.
- attrNameAfter: The name of the attribute, after renaming.
*/
/* istanbul ignore next */
renameColumnQuery(tableName, attrNameBefore, attrNameAfter) {
throwMethodUndefined('renameColumnQuery');
},
/*
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs. Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
@private
*/ */
insertQuery(table, valueHash, modelAttributes, options) { insertQuery(table, valueHash, modelAttributes, options) {
options = options || {}; options = options || {};
...@@ -312,6 +213,7 @@ const QueryGenerator = { ...@@ -312,6 +213,7 @@ const QueryGenerator = {
/* /*
Returns an insert into command for multiple values. Returns an insert into command for multiple values.
Parameters: table name + list of hashes of attribute-value-pairs. Parameters: table name + list of hashes of attribute-value-pairs.
@private
*/ */
bulkInsertQuery(tableName, attrValueHashes, options, rawAttributes) { bulkInsertQuery(tableName, attrValueHashes, options, rawAttributes) {
options = options || {}; options = options || {};
...@@ -373,6 +275,7 @@ const QueryGenerator = { ...@@ -373,6 +275,7 @@ const QueryGenerator = {
OR an ID as integer OR an ID as integer
OR a string with conditions (e.g. 'name="foo"'). OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own. If you use a string, you have to escape it on your own.
@private
*/ */
updateQuery(tableName, attrValueHash, where, options, attributes) { updateQuery(tableName, attrValueHash, where, options, attributes) {
options = options || {}; options = options || {};
...@@ -469,34 +372,6 @@ const QueryGenerator = { ...@@ -469,34 +372,6 @@ const QueryGenerator = {
}, },
/* /*
Returns an upsert query.
*/
upsertQuery(tableName, insertValues, updateValues, where, rawAttributes, options) {
throwMethodUndefined('upsertQuery');
},
/*
Returns a deletion query.
Parameters:
- tableName -> Name of the table
- where -> A hash with conditions (e.g. {name: 'foo'})
OR an ID as integer
OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own.
Options:
- limit -> Maximaum count of lines to delete
- truncate -> boolean - whether to use an 'optimized' mechanism (i.e. TRUNCATE) if available,
note that this should not be the default behaviour because TRUNCATE does not
always play nicely (e.g. InnoDB tables with FK constraints)
(@see http://dev.mysql.com/doc/refman/5.6/en/truncate-table.html).
Note that truncate must ignore limit and where
*/
/* istanbul ignore next */
deleteQuery(tableName, where, options) {
throwMethodUndefined('deleteQuery');
},
/*
Returns an update query. Returns an update query.
Parameters: Parameters:
- tableName -> Name of the table - tableName -> Name of the table
...@@ -505,6 +380,7 @@ const QueryGenerator = { ...@@ -505,6 +380,7 @@ const QueryGenerator = {
OR an ID as integer OR an ID as integer
OR a string with conditions (e.g. 'name="foo"'). OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own. If you use a string, you have to escape it on your own.
@private
*/ */
incrementQuery(tableName, attrValueHash, where, options) { incrementQuery(tableName, attrValueHash, where, options) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull); attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull);
...@@ -567,6 +443,7 @@ const QueryGenerator = { ...@@ -567,6 +443,7 @@ const QueryGenerator = {
- order: 'ASC' or 'DESC'. Optional - order: 'ASC' or 'DESC'. Optional
- parser - parser
- rawTablename, the name of the table, without schema. Used to create the name of the index - rawTablename, the name of the table, without schema. Used to create the name of the index
@private
*/ */
addIndexQuery(tableName, attributes, options, rawTablename) { addIndexQuery(tableName, attributes, options, rawTablename) {
options = options || {}; options = options || {};
...@@ -680,47 +557,6 @@ const QueryGenerator = { ...@@ -680,47 +557,6 @@ const QueryGenerator = {
return Utils._.compact(ind).join(' '); return Utils._.compact(ind).join(' ');
}, },
/*
Returns a query listing indexes for a given table.
Parameters:
- tableName: Name of an existing table.
- options:
- database: Name of the database.
*/
/* istanbul ignore next */
showIndexesQuery(tableName, options) {
throwMethodUndefined('showIndexesQuery');
},
/*
Returns a remove index query.
Parameters:
- tableName: Name of an existing table.
- indexNameOrAttributes: The name of the index as string or an array of attribute names.
*/
/* istanbul ignore next */
removeIndexQuery(tableName, indexNameOrAttributes) {
throwMethodUndefined('removeIndexQuery');
},
/*
This method transforms an array of attribute hashes into equivalent
sql attribute definition.
*/
/* istanbul ignore next */
attributesToSQL(attributes) {
throwMethodUndefined('attributesToSQL');
},
/*
Returns all auto increment fields of a factory.
*/
/* istanbul ignore next */
findAutoIncrementField(factory) {
throwMethodUndefined('findAutoIncrementField');
},
quoteTable(param, as) { quoteTable(param, as) {
let table = ''; let table = '';
...@@ -775,6 +611,7 @@ const QueryGenerator = { ...@@ -775,6 +611,7 @@ const QueryGenerator = {
Currently this function is only used for ordering / grouping columns and Sequelize.col(), but it could Currently this function is only used for ordering / grouping columns and Sequelize.col(), but it could
potentially also be used for other places where we want to be able to call SQL functions (e.g. as default values) potentially also be used for other places where we want to be able to call SQL functions (e.g. as default values)
@private
*/ */
quote(obj, parent, force) { quote(obj, parent, force) {
if (Utils._.isString(obj)) { if (Utils._.isString(obj)) {
...@@ -845,65 +682,10 @@ const QueryGenerator = { ...@@ -845,65 +682,10 @@ const QueryGenerator = {
}, },
/* /*
Create a trigger
*/
/* istanbul ignore next */
createTrigger(tableName, triggerName, timingType, fireOnArray, functionName, functionParams, optionsArray) {
throwMethodUndefined('createTrigger');
},
/*
Drop a trigger
*/
/* istanbul ignore next */
dropTrigger(tableName, triggerName) {
throwMethodUndefined('dropTrigger');
},
/*
Rename a trigger
*/
/* istanbul ignore next */
renameTrigger(tableName, oldTriggerName, newTriggerName) {
throwMethodUndefined('renameTrigger');
},
/*
Create a function
*/
/* istanbul ignore next */
createFunction(functionName, params, returnType, language, body, options) {
throwMethodUndefined('createFunction');
},
/*
Drop a function
*/
/* istanbul ignore next */
dropFunction(functionName, params) {
throwMethodUndefined('dropFunction');
},
/*
Rename a function
*/
/* istanbul ignore next */
renameFunction(oldFunctionName, params, newFunctionName) {
throwMethodUndefined('renameFunction');
},
/*
Escape an identifier (e.g. a table or attribute name)
*/
/* istanbul ignore next */
quoteIdentifier(identifier, force) {
throwMethodUndefined('quoteIdentifier');
},
/*
Split an identifier into .-separated tokens and quote each part Split an identifier into .-separated tokens and quote each part
@private
*/ */
quoteIdentifiers(identifiers, force) { quoteIdentifiers(identifiers) {
if (identifiers.indexOf('.') !== -1) { if (identifiers.indexOf('.') !== -1) {
identifiers = identifiers.split('.'); identifiers = identifiers.split('.');
return this.quoteIdentifier(identifiers.slice(0, identifiers.length - 1).join('.')) + '.' + this.quoteIdentifier(identifiers[identifiers.length - 1]); return this.quoteIdentifier(identifiers.slice(0, identifiers.length - 1).join('.')) + '.' + this.quoteIdentifier(identifiers[identifiers.length - 1]);
...@@ -914,6 +696,7 @@ const QueryGenerator = { ...@@ -914,6 +696,7 @@ const QueryGenerator = {
/* /*
Escape a value (e.g. a string, number or date) Escape a value (e.g. a string, number or date)
@private
*/ */
escape(value, field, options) { escape(value, field, options) {
options = options || {}; options = options || {};
...@@ -951,31 +734,6 @@ const QueryGenerator = { ...@@ -951,31 +734,6 @@ const QueryGenerator = {
return SqlString.escape(value, this.options.timezone, this.dialect); return SqlString.escape(value, this.options.timezone, this.dialect);
}, },
/**
* Generates an SQL query that returns all foreign keys of a table.
*
* @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema.
* @return {String} The generated sql query.
*/
/* istanbul ignore next */
getForeignKeysQuery(tableName, schemaName) {
throwMethodUndefined('getForeignKeysQuery');
},
/**
* Generates an SQL query that removes a foreign key from a table.
*
* @param {String} tableName The name of the table.
* @param {String} foreignKey The name of the foreign key constraint.
* @return {String} The generated sql query.
*/
/* istanbul ignore next */
dropForeignKeyQuery(tableName, foreignKey) {
throwMethodUndefined('dropForeignKeyQuery');
},
/* /*
Returns a query for selecting elements in the table <tableName>. Returns a query for selecting elements in the table <tableName>.
Options: Options:
...@@ -988,6 +746,7 @@ const QueryGenerator = { ...@@ -988,6 +746,7 @@ const QueryGenerator = {
- group - group
- limit -> The maximum count you want to get. - limit -> The maximum count you want to get.
- offset -> An offset value to start from. Only useable with limit! - offset -> An offset value to start from. Only useable with limit!
@private
*/ */
selectQuery(tableName, options, model) { selectQuery(tableName, options, model) {
...@@ -1731,6 +1490,7 @@ const QueryGenerator = { ...@@ -1731,6 +1490,7 @@ const QueryGenerator = {
* @param {Boolean} value A boolean that states whether autocommit shall be done or not. * @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
setAutocommitQuery(value, options) { setAutocommitQuery(value, options) {
if (options.parent) { if (options.parent) {
...@@ -1751,6 +1511,7 @@ const QueryGenerator = { ...@@ -1751,6 +1511,7 @@ const QueryGenerator = {
* @param {String} value The isolation level. * @param {String} value The isolation level.
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
setIsolationLevelQuery(value, options) { setIsolationLevelQuery(value, options) {
if (options.parent) { if (options.parent) {
...@@ -1766,6 +1527,7 @@ const QueryGenerator = { ...@@ -1766,6 +1527,7 @@ const QueryGenerator = {
* @param {Transaction} transaction * @param {Transaction} transaction
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
startTransactionQuery(transaction) { startTransactionQuery(transaction) {
if (transaction.parent) { if (transaction.parent) {
...@@ -1782,6 +1544,7 @@ const QueryGenerator = { ...@@ -1782,6 +1544,7 @@ const QueryGenerator = {
* @param {Transaction} transaction * @param {Transaction} transaction
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
deferConstraintsQuery() {}, deferConstraintsQuery() {},
...@@ -1794,6 +1557,7 @@ const QueryGenerator = { ...@@ -1794,6 +1557,7 @@ const QueryGenerator = {
* *
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
commitTransactionQuery(transaction) { commitTransactionQuery(transaction) {
if (transaction.parent) { if (transaction.parent) {
...@@ -1809,6 +1573,7 @@ const QueryGenerator = { ...@@ -1809,6 +1573,7 @@ const QueryGenerator = {
* @param {Transaction} transaction * @param {Transaction} transaction
* @param {Object} options An object with options. * @param {Object} options An object with options.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
rollbackTransactionQuery(transaction) { rollbackTransactionQuery(transaction) {
if (transaction.parent) { if (transaction.parent) {
...@@ -1825,8 +1590,9 @@ const QueryGenerator = { ...@@ -1825,8 +1590,9 @@ const QueryGenerator = {
* @param {Object} options An object with selectQuery options. * @param {Object} options An object with selectQuery options.
* @param {Object} options The model passed to the selectQuery. * @param {Object} options The model passed to the selectQuery.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
addLimitAndOffset(options, model) { addLimitAndOffset(options) {
let fragment = ''; let fragment = '';
/*jshint eqeqeq:false*/ /*jshint eqeqeq:false*/
...@@ -2328,6 +2094,7 @@ const QueryGenerator = { ...@@ -2328,6 +2094,7 @@ const QueryGenerator = {
/* /*
Takes something and transforms it into values of a where condition. Takes something and transforms it into values of a where condition.
@private
*/ */
getWhereConditions(smth, tableName, factory, options, prepend) { getWhereConditions(smth, tableName, factory, options, prepend) {
let result = null; let result = null;
......
...@@ -19,6 +19,7 @@ class AbstractQuery { ...@@ -19,6 +19,7 @@ class AbstractQuery {
* Options * Options
* skipUnescape: bool, skip unescaping $$ * skipUnescape: bool, skip unescaping $$
* skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available * skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available
* @private
*/ */
static formatBindParameters(sql, values, dialect, replacementFunc, options) { static formatBindParameters(sql, values, dialect, replacementFunc, options) {
if (!values) { if (!values) {
...@@ -94,7 +95,7 @@ class AbstractQuery { ...@@ -94,7 +95,7 @@ class AbstractQuery {
* query.run('SELECT 1') * query.run('SELECT 1')
* *
* @param {String} sql - The SQL query which should be executed. * @param {String} sql - The SQL query which should be executed.
* @api public * @private
*/ */
run() { run() {
throw new Error('The run method wasn\'t overwritten!'); throw new Error('The run method wasn\'t overwritten!');
...@@ -104,6 +105,7 @@ class AbstractQuery { ...@@ -104,6 +105,7 @@ class AbstractQuery {
* Check the logging option of the instance and print deprecation warnings. * Check the logging option of the instance and print deprecation warnings.
* *
* @return {void} * @return {void}
* @private
*/ */
checkLoggingOption() { checkLoggingOption() {
if (this.options.logging === true) { if (this.options.logging === true) {
...@@ -116,6 +118,7 @@ class AbstractQuery { ...@@ -116,6 +118,7 @@ class AbstractQuery {
* Get the attributes of an insert query, which contains the just inserted id. * Get the attributes of an insert query, which contains the just inserted id.
* *
* @return {String} The field name. * @return {String} The field name.
* @private
*/ */
getInsertIdField() { getInsertIdField() {
return 'insertId'; return 'insertId';
...@@ -127,6 +130,7 @@ class AbstractQuery { ...@@ -127,6 +130,7 @@ class AbstractQuery {
* *
* @param {String} attribute An attribute of a SQL query. (?) * @param {String} attribute An attribute of a SQL query. (?)
* @return {String} The found tableName / alias. * @return {String} The found tableName / alias.
* @private
*/ */
findTableNameInAttribute(attribute) { findTableNameInAttribute(attribute) {
if (!this.options.include) { if (!this.options.include) {
...@@ -353,6 +357,7 @@ class AbstractQuery { ...@@ -353,6 +357,7 @@ class AbstractQuery {
* ] * ]
* } * }
* ] * ]
* @private
*/ */
static _groupJoinData(rows, includeOptions, options) { static _groupJoinData(rows, includeOptions, options) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
@class QueryInterface @class QueryInterface
@static @static
@private
*/ */
/** /**
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
@param {String} attributeName The name of the attribute that we want to remove. @param {String} attributeName The name of the attribute that we want to remove.
@param {Object} options @param {Object} options
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries @param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@private
*/ */
var removeColumn = function(tableName, attributeName, options) { var removeColumn = function(tableName, attributeName, options) {
var self = this; var self = this;
......
...@@ -128,6 +128,7 @@ class Query extends AbstractQuery { ...@@ -128,6 +128,7 @@ class Query extends AbstractQuery {
* ]) * ])
* *
* @param {Array} data - The result of the query execution. * @param {Array} data - The result of the query execution.
* @private
*/ */
formatResults(data) { formatResults(data) {
let result = this.instance; let result = this.instance;
......
...@@ -17,6 +17,7 @@ const parserMap = new Map(); ...@@ -17,6 +17,7 @@ const parserMap = new Map();
* *
* @extends AbstractConnectionManager * @extends AbstractConnectionManager
* @return Class<ConnectionManager> * @return Class<ConnectionManager>
* @private
*/ */
class ConnectionManager extends AbstractConnectionManager { class ConnectionManager extends AbstractConnectionManager {
...@@ -65,6 +66,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -65,6 +66,7 @@ class ConnectionManager extends AbstractConnectionManager {
* Also set proper timezone once conection is connected * Also set proper timezone once conection is connected
* *
* @return Promise<Connection> * @return Promise<Connection>
* @private
*/ */
connect(config) { connect(config) {
const connectionConfig = { const connectionConfig = {
......
...@@ -302,6 +302,7 @@ const QueryGenerator = { ...@@ -302,6 +302,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table. * @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema. * @param {String} schemaName The name of the schema.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
getForeignKeysQuery(tableName, schemaName) { getForeignKeysQuery(tableName, schemaName) {
return "SELECT CONSTRAINT_NAME as constraint_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where TABLE_NAME = '" + tableName + /* jshint ignore: line */ return "SELECT CONSTRAINT_NAME as constraint_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where TABLE_NAME = '" + tableName + /* jshint ignore: line */
...@@ -314,6 +315,7 @@ const QueryGenerator = { ...@@ -314,6 +315,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table. * @param {String} tableName The name of the table.
* @param {String} columnName The name of the column. * @param {String} columnName The name of the column.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
getForeignKeyQuery(table, columnName) { getForeignKeyQuery(table, columnName) {
let tableName = table.tableName || table; let tableName = table.tableName || table;
...@@ -335,6 +337,7 @@ const QueryGenerator = { ...@@ -335,6 +337,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table. * @param {String} tableName The name of the table.
* @param {String} foreignKey The name of the foreign key constraint. * @param {String} foreignKey The name of the foreign key constraint.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
dropForeignKeyQuery(tableName, foreignKey) { dropForeignKeyQuery(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP FOREIGN KEY ' + this.quoteIdentifier(foreignKey) + ';'; return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP FOREIGN KEY ' + this.quoteIdentifier(foreignKey) + ';';
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
@class QueryInterface @class QueryInterface
@static @static
@private
*/ */
const _ = require('lodash'); const _ = require('lodash');
...@@ -18,6 +19,7 @@ const _ = require('lodash'); ...@@ -18,6 +19,7 @@ const _ = require('lodash');
@param {String} tableName The name of the table. @param {String} tableName The name of the table.
@param {String} columnName The name of the attribute that we want to remove. @param {String} columnName The name of the attribute that we want to remove.
@param {Object} options @param {Object} options
@private
*/ */
function removeColumn(tableName, columnName, options) { function removeColumn(tableName, columnName, options) {
options = options || {}; options = options || {};
......
...@@ -84,6 +84,7 @@ class Query extends AbstractQuery { ...@@ -84,6 +84,7 @@ class Query extends AbstractQuery {
* ]) * ])
* *
* @param {Array} data - The result of the query execution. * @param {Array} data - The result of the query execution.
* @private
*/ */
formatResults(data) { formatResults(data) {
let result = this.instance; let result = this.instance;
......
...@@ -769,6 +769,7 @@ const QueryGenerator = { ...@@ -769,6 +769,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table. * @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema. * @param {String} schemaName The name of the schema.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
getForeignKeysQuery(tableName, schemaName) { getForeignKeysQuery(tableName, schemaName) {
return 'SELECT conname as constraint_name, pg_catalog.pg_get_constraintdef(r.oid, true) as condef FROM pg_catalog.pg_constraint r ' + return 'SELECT conname as constraint_name, pg_catalog.pg_get_constraintdef(r.oid, true) as condef FROM pg_catalog.pg_constraint r ' +
...@@ -781,6 +782,7 @@ const QueryGenerator = { ...@@ -781,6 +782,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table. * @param {String} tableName The name of the table.
* @param {String} foreignKey The name of the foreign key constraint. * @param {String} foreignKey The name of the foreign key constraint.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
dropForeignKeyQuery(tableName, foreignKey) { dropForeignKeyQuery(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP CONSTRAINT ' + this.quoteIdentifier(foreignKey) + ';'; return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP CONSTRAINT ' + this.quoteIdentifier(foreignKey) + ';';
......
...@@ -26,6 +26,7 @@ class Query extends AbstractQuery { ...@@ -26,6 +26,7 @@ class Query extends AbstractQuery {
/** /**
* rewrite query with parameters * rewrite query with parameters
* @private
*/ */
static formatBindParameters(sql, values, dialect) { static formatBindParameters(sql, values, dialect) {
let bindParam = []; let bindParam = [];
......
...@@ -341,6 +341,7 @@ const QueryGenerator = { ...@@ -341,6 +341,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table. * @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema. * @param {String} schemaName The name of the schema.
* @return {String} The generated sql query. * @return {String} The generated sql query.
* @private
*/ */
getForeignKeysQuery(tableName, schemaName) { getForeignKeysQuery(tableName, schemaName) {
return `PRAGMA foreign_key_list(${tableName})`; return `PRAGMA foreign_key_list(${tableName})`;
......
...@@ -8,6 +8,7 @@ const Promise = require('../../promise'); ...@@ -8,6 +8,7 @@ const Promise = require('../../promise');
@class QueryInterface @class QueryInterface
@static @static
@private
*/ */
/** /**
...@@ -24,6 +25,7 @@ const Promise = require('../../promise'); ...@@ -24,6 +25,7 @@ const Promise = require('../../promise');
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries @param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@since 1.6.0 @since 1.6.0
@private
*/ */
function removeColumn(tableName, attributeName, options) { function removeColumn(tableName, attributeName, options) {
options = options || {}; options = options || {};
...@@ -54,6 +56,7 @@ exports.removeColumn = removeColumn; ...@@ -54,6 +56,7 @@ exports.removeColumn = removeColumn;
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries @param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@since 1.6.0 @since 1.6.0
@private
*/ */
function changeColumn(tableName, attributes, options) { function changeColumn(tableName, attributes, options) {
const attributeName = Object.keys(attributes)[0]; const attributeName = Object.keys(attributes)[0];
...@@ -86,6 +89,7 @@ exports.changeColumn = changeColumn; ...@@ -86,6 +89,7 @@ exports.changeColumn = changeColumn;
@param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries @param {Boolean|Function} [options.logging] A function that logs the sql queries, or false for explicitly not logging these queries
@since 1.6.0 @since 1.6.0
@private
*/ */
function renameColumn(tableName, attrNameBefore, attrNameAfter, options) { function renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
options = options || {}; options = options || {};
......
...@@ -32,6 +32,7 @@ class Query extends AbstractQuery { ...@@ -32,6 +32,7 @@ class Query extends AbstractQuery {
/** /**
* rewrite query with parameters * rewrite query with parameters
* @private
*/ */
static formatBindParameters(sql, values, dialect) { static formatBindParameters(sql, values, dialect) {
let bindParam; let bindParam;
......
...@@ -4,15 +4,16 @@ ...@@ -4,15 +4,16 @@
* Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors are exposed on the sequelize object and the sequelize constructor. * Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors are exposed on the sequelize object and the sequelize constructor.
* All sequelize errors inherit from the base JS error object. * All sequelize errors inherit from the base JS error object.
* *
* @fileOverview The Error Objects produced by Sequelize. * This means that errors can be accessed using `Sequelize.ValidationError` or `sequelize.ValidationError
* @class Errors *
* @namespace Errors
*/ */
/** /**
* The Base Error all Sequelize Errors inherit from. * The Base Error all Sequelize Errors inherit from.
* *
* @constructor
* @alias Error * @alias Error
* @memberof Errors
*/ */
class BaseError extends Error { class BaseError extends Error {
constructor(message) { constructor(message) {
...@@ -30,7 +31,7 @@ exports.BaseError = BaseError; ...@@ -30,7 +31,7 @@ exports.BaseError = BaseError;
* @param {string} message Error message * @param {string} message Error message
* *
* @extends BaseError * @extends BaseError
* @constructor * @memberof Errors
*/ */
class SequelizeScopeError extends BaseError { class SequelizeScopeError extends BaseError {
constructor(parent) { constructor(parent) {
...@@ -48,17 +49,15 @@ exports.SequelizeScopeError = SequelizeScopeError; ...@@ -48,17 +49,15 @@ exports.SequelizeScopeError = SequelizeScopeError;
* @param {Array} [errors] Array of ValidationErrorItem objects describing the validation errors * @param {Array} [errors] Array of ValidationErrorItem objects describing the validation errors
* *
* @extends BaseError * @extends BaseError
* @constructor * @memberof Errors
*
* @property errors An array of ValidationErrorItems
*/ */
class ValidationError extends BaseError { class ValidationError extends BaseError {
constructor(message, errors) { constructor(message, errors) {
super(message); super(message);
this.name = 'SequelizeValidationError'; this.name = 'SequelizeValidationError';
this.message = 'Validation Error'; this.message = 'Validation Error';
/**
* An array of ValidationErrorItems
* @member errors
*/
this.errors = errors || []; this.errors = errors || [];
// Use provided error message if available... // Use provided error message if available...
...@@ -91,43 +90,23 @@ exports.ValidationError = ValidationError; ...@@ -91,43 +90,23 @@ exports.ValidationError = ValidationError;
/** /**
* A base class for all database related errors. * A base class for all database related errors.
* @extends BaseError * @extends BaseError
* @constructor * @class DatabaseError
* @memberof Errors
*
* @property parent The database specific error which triggered this one
* @property sql The SQL that triggered the error
* @property message The message from the DB.
* @property fields The fields of the unique constraint
* @property value The value(s) which triggered the error
* @property index The name of the index that triggered the error
*/ */
class DatabaseError extends BaseError { class DatabaseError extends BaseError {
constructor(parent) { constructor(parent) {
super(parent.message); super(parent.message);
this.name = 'SequelizeDatabaseError'; this.name = 'SequelizeDatabaseError';
/**
* The database specific error which triggered this one
* @member parent
*/
this.parent = parent; this.parent = parent;
this.original = parent; this.original = parent;
/**
* The SQL that triggered the error
* @member sql
*/
this.sql = parent.sql; this.sql = parent.sql;
/**
* The message from the DB.
* @member message
* @name message
*/
/**
* The fields of the unique constraint
* @member fields
* @name fields
*/
/**
* The value(s) which triggered the error
* @member value
* @name value
*/
/**
* The name of the index that triggered the error
* @member index
* @name index
*/
} }
} }
exports.DatabaseError = DatabaseError; exports.DatabaseError = DatabaseError;
...@@ -135,7 +114,7 @@ exports.DatabaseError = DatabaseError; ...@@ -135,7 +114,7 @@ exports.DatabaseError = DatabaseError;
/** /**
* Thrown when a database query times out because of a deadlock * Thrown when a database query times out because of a deadlock
* @extends DatabaseError * @extends DatabaseError
* @constructor * @memberof Errors
*/ */
class TimeoutError extends DatabaseError { class TimeoutError extends DatabaseError {
constructor(parent) { constructor(parent) {
...@@ -148,7 +127,10 @@ exports.TimeoutError = TimeoutError; ...@@ -148,7 +127,10 @@ exports.TimeoutError = TimeoutError;
/** /**
* Thrown when a unique constraint is violated in the database * Thrown when a unique constraint is violated in the database
* @extends DatabaseError * @extends DatabaseError
* @constructor * @memberof Errors
*
* @property
* @property sql
*/ */
class UniqueConstraintError extends ValidationError { class UniqueConstraintError extends ValidationError {
constructor(options) { constructor(options) {
...@@ -172,7 +154,7 @@ exports.UniqueConstraintError = UniqueConstraintError; ...@@ -172,7 +154,7 @@ exports.UniqueConstraintError = UniqueConstraintError;
/** /**
* Thrown when a foreign key constraint is violated in the database * Thrown when a foreign key constraint is violated in the database
* @extends DatabaseError * @extends DatabaseError
* @constructor * @memberof Errors
*/ */
class ForeignKeyConstraintError extends DatabaseError { class ForeignKeyConstraintError extends DatabaseError {
constructor(options) { constructor(options) {
...@@ -194,7 +176,7 @@ exports.ForeignKeyConstraintError = ForeignKeyConstraintError; ...@@ -194,7 +176,7 @@ exports.ForeignKeyConstraintError = ForeignKeyConstraintError;
/** /**
* Thrown when an exclusion constraint is violated in the database * Thrown when an exclusion constraint is violated in the database
* @extends DatabaseError * @extends DatabaseError
* @constructor * @memberof Errors
*/ */
class ExclusionConstraintError extends DatabaseError { class ExclusionConstraintError extends DatabaseError {
constructor(options) { constructor(options) {
...@@ -220,7 +202,7 @@ exports.ExclusionConstraintError = ExclusionConstraintError; ...@@ -220,7 +202,7 @@ exports.ExclusionConstraintError = ExclusionConstraintError;
* @param {string} type The type of the validation error * @param {string} type The type of the validation error
* @param {string} path The field that triggered the validation error * @param {string} path The field that triggered the validation error
* @param {string} value The value that generated the error * @param {string} value The value that generated the error
* @constructor * @memberof Errors
*/ */
class ValidationErrorItem { class ValidationErrorItem {
constructor(message, type, path, value) { constructor(message, type, path, value) {
...@@ -235,16 +217,14 @@ exports.ValidationErrorItem = ValidationErrorItem; ...@@ -235,16 +217,14 @@ exports.ValidationErrorItem = ValidationErrorItem;
/** /**
* A base class for all connection related errors. * A base class for all connection related errors.
* @extends BaseError * @extends BaseError
* @constructor * @memberof Errors
*
* @property parent The connection specific error which triggered this one
*/ */
class ConnectionError extends BaseError { class ConnectionError extends BaseError {
constructor(parent) { constructor(parent) {
super(parent ? parent.message : ''); super(parent ? parent.message : '');
this.name = 'SequelizeConnectionError'; this.name = 'SequelizeConnectionError';
/**
* The connection specific error which triggered this one
* @member parent
*/
this.parent = parent; this.parent = parent;
this.original = parent; this.original = parent;
} }
...@@ -254,7 +234,7 @@ exports.ConnectionError = ConnectionError; ...@@ -254,7 +234,7 @@ exports.ConnectionError = ConnectionError;
/** /**
* Thrown when a connection to a database is refused * Thrown when a connection to a database is refused
* @extends ConnectionError * @extends ConnectionError
* @constructor * @memberof Errors
*/ */
class ConnectionRefusedError extends ConnectionError { class ConnectionRefusedError extends ConnectionError {
constructor(parent) { constructor(parent) {
...@@ -267,7 +247,7 @@ exports.ConnectionRefusedError = ConnectionRefusedError; ...@@ -267,7 +247,7 @@ exports.ConnectionRefusedError = ConnectionRefusedError;
/** /**
* Thrown when a connection to a database is refused due to insufficient privileges * Thrown when a connection to a database is refused due to insufficient privileges
* @extends ConnectionError * @extends ConnectionError
* @constructor * @memberof Errors
*/ */
class AccessDeniedError extends ConnectionError { class AccessDeniedError extends ConnectionError {
constructor(parent) { constructor(parent) {
...@@ -280,7 +260,7 @@ exports.AccessDeniedError = AccessDeniedError; ...@@ -280,7 +260,7 @@ exports.AccessDeniedError = AccessDeniedError;
/** /**
* Thrown when a connection to a database has a hostname that was not found * Thrown when a connection to a database has a hostname that was not found
* @extends ConnectionError * @extends ConnectionError
* @constructor * @memberof Errors
*/ */
class HostNotFoundError extends ConnectionError { class HostNotFoundError extends ConnectionError {
constructor(parent) { constructor(parent) {
...@@ -293,7 +273,7 @@ exports.HostNotFoundError = HostNotFoundError; ...@@ -293,7 +273,7 @@ exports.HostNotFoundError = HostNotFoundError;
/** /**
* Thrown when a connection to a database has a hostname that was not reachable * Thrown when a connection to a database has a hostname that was not reachable
* @extends ConnectionError * @extends ConnectionError
* @constructor * @memberof Errors
*/ */
class HostNotReachableError extends ConnectionError { class HostNotReachableError extends ConnectionError {
constructor(parent) { constructor(parent) {
...@@ -306,7 +286,7 @@ exports.HostNotReachableError = HostNotReachableError; ...@@ -306,7 +286,7 @@ exports.HostNotReachableError = HostNotReachableError;
/** /**
* Thrown when a connection to a database has invalid values for any of the connection parameters * Thrown when a connection to a database has invalid values for any of the connection parameters
* @extends ConnectionError * @extends ConnectionError
* @constructor * @memberof Errors
*/ */
class InvalidConnectionError extends ConnectionError { class InvalidConnectionError extends ConnectionError {
constructor(parent) { constructor(parent) {
...@@ -319,7 +299,7 @@ exports.InvalidConnectionError = InvalidConnectionError; ...@@ -319,7 +299,7 @@ exports.InvalidConnectionError = InvalidConnectionError;
/** /**
* Thrown when a connection to a database times out * Thrown when a connection to a database times out
* @extends ConnectionError * @extends ConnectionError
* @constructor * @memberof Errors
*/ */
class ConnectionTimedOutError extends ConnectionError { class ConnectionTimedOutError extends ConnectionError {
constructor(parent) { constructor(parent) {
...@@ -332,7 +312,7 @@ exports.ConnectionTimedOutError = ConnectionTimedOutError; ...@@ -332,7 +312,7 @@ exports.ConnectionTimedOutError = ConnectionTimedOutError;
/** /**
* Thrown when a some problem occurred with Instance methods (see message for details) * Thrown when a some problem occurred with Instance methods (see message for details)
* @extends BaseError * @extends BaseError
* @constructor * @memberof Errors
*/ */
class InstanceError extends BaseError { class InstanceError extends BaseError {
constructor(message) { constructor(message) {
...@@ -346,7 +326,7 @@ exports.InstanceError = InstanceError; ...@@ -346,7 +326,7 @@ exports.InstanceError = InstanceError;
/** /**
* Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details) * Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details)
* @extends BaseError * @extends BaseError
* @constructor * @memberof Errors
*/ */
class EmptyResultError extends BaseError { class EmptyResultError extends BaseError {
constructor(message) { constructor(message) {
......
...@@ -4,38 +4,6 @@ const Utils = require('./utils'); ...@@ -4,38 +4,6 @@ const Utils = require('./utils');
const Promise = require('./promise'); const Promise = require('./promise');
const debug = Utils.getLogger().debugContext('hooks'); const debug = Utils.getLogger().debugContext('hooks');
/**
* Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:
*
* 1. By specifying them as options in `sequelize.define`
* 2. By calling `hook()` with a string and your hook handler function
* 3. By calling the function with the same name as the hook you want
* ```js
* // Method 1
* sequelize.define(name, { attributes }, {
* hooks: {
* beforeBulkCreate() {
* // can be a single function
* },
* beforeValidate: [
* function() {},
* function() {} // Or an array of several
* ]
* }
* })
*
* // Method 2
* Model.hook('afterDestroy', function () {})
*
* // Method 3
* Model.afterBulkUpdate(function () {})
* ```
*
* @see {Sequelize#define}
* @mixin Hooks
* @name Hooks
*/
const hookTypes = { const hookTypes = {
beforeValidate: {params: 2}, beforeValidate: {params: 2},
afterValidate: {params: 2}, afterValidate: {params: 2},
...@@ -88,6 +56,7 @@ exports.hookAliases = hookAliases; ...@@ -88,6 +56,7 @@ exports.hookAliases = hookAliases;
/** /**
* get array of current hook and its proxied hooks combined * get array of current hook and its proxied hooks combined
* @private
*/ */
const getProxiedHooks = (hookType) => ( const getProxiedHooks = (hookType) => (
hookTypes[hookType].proxies hookTypes[hookType].proxies
...@@ -160,11 +129,12 @@ const Hooks = { ...@@ -160,11 +129,12 @@ const Hooks = {
/** /**
* Add a hook to the model * Add a hook to the model
* *
* @param {String} hooktype * @param {String} hookType
* @param {String} [name] Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future. * @param {String} [name] Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future.
* @param {Function} fn The hook function * @param {Function} fn The hook function
* *
* @alias hook * @memberOf Sequelize
* @memberOf Sequelize.Model
*/ */
addHook(hookType, name, fn) { addHook(hookType, name, fn) {
if (typeof name === 'function') { if (typeof name === 'function') {
...@@ -191,6 +161,9 @@ const Hooks = { ...@@ -191,6 +161,9 @@ const Hooks = {
* *
* @param {String} hookType * @param {String} hookType
* @param {String|Function} name * @param {String|Function} name
*
* @memberOf Sequelize
* @memberOf Sequelize.Model
*/ */
removeHook(hookType, name) { removeHook(hookType, name) {
hookType = hookAliases[hookType] || hookType; hookType = hookAliases[hookType] || hookType;
...@@ -218,12 +191,14 @@ const Hooks = { ...@@ -218,12 +191,14 @@ const Hooks = {
return this; return this;
}, },
/* /**
* Check whether the mode has any hooks of this type * Check whether the mode has any hooks of this type
* *
* @param {String} hookType * @param {String} hookType
* *
* @alias hasHooks * @alias hasHooks
* @memberOf Sequelize
* @memberOf Sequelize.Model
*/ */
hasHook(hookType) { hasHook(hookType) {
return this.options.hooks[hookType] && !!this.options.hooks[hookType].length; return this.options.hooks[hookType] && !!this.options.hooks[hookType].length;
...@@ -249,6 +224,7 @@ exports.applyTo = applyTo; ...@@ -249,6 +224,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instance, options * @param {Function} fn A callback function that is called with instance, options
* @name beforeValidate * @name beforeValidate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -256,6 +232,7 @@ exports.applyTo = applyTo; ...@@ -256,6 +232,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instance, options * @param {Function} fn A callback function that is called with instance, options
* @name afterValidate * @name afterValidate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -264,6 +241,7 @@ exports.applyTo = applyTo; ...@@ -264,6 +241,7 @@ exports.applyTo = applyTo;
* @param {Function} fn A callback function that is called with instance, options, error. Error is the * @param {Function} fn A callback function that is called with instance, options, error. Error is the
* SequelizeValidationError. If the callback throws an error, it will replace the original validation error. * SequelizeValidationError. If the callback throws an error, it will replace the original validation error.
* @name validationFailed * @name validationFailed
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -271,6 +249,7 @@ exports.applyTo = applyTo; ...@@ -271,6 +249,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name beforeCreate * @name beforeCreate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -278,6 +257,7 @@ exports.applyTo = applyTo; ...@@ -278,6 +257,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name afterCreate * @name afterCreate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -285,6 +265,7 @@ exports.applyTo = applyTo; ...@@ -285,6 +265,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name beforeSave * @name beforeSave
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -292,6 +273,7 @@ exports.applyTo = applyTo; ...@@ -292,6 +273,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name beforeUpsert * @name beforeUpsert
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -299,6 +281,7 @@ exports.applyTo = applyTo; ...@@ -299,6 +281,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name afterUpsert * @name afterUpsert
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -306,6 +289,7 @@ exports.applyTo = applyTo; ...@@ -306,6 +289,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name afterSave * @name afterSave
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -315,6 +299,7 @@ exports.applyTo = applyTo; ...@@ -315,6 +299,7 @@ exports.applyTo = applyTo;
* *
* @name beforeDestroy * @name beforeDestroy
* @alias beforeDelete * @alias beforeDelete
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -324,6 +309,7 @@ exports.applyTo = applyTo; ...@@ -324,6 +309,7 @@ exports.applyTo = applyTo;
* *
* @name afterDestroy * @name afterDestroy
* @alias afterDelete * @alias afterDelete
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -332,6 +318,7 @@ exports.applyTo = applyTo; ...@@ -332,6 +318,7 @@ exports.applyTo = applyTo;
* @param {Function} fn A callback function that is called with instance, options * @param {Function} fn A callback function that is called with instance, options
* *
* @name beforeRestore * @name beforeRestore
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -340,6 +327,7 @@ exports.applyTo = applyTo; ...@@ -340,6 +327,7 @@ exports.applyTo = applyTo;
* @param {Function} fn A callback function that is called with instance, options * @param {Function} fn A callback function that is called with instance, options
* *
* @name afterRestore * @name afterRestore
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -347,6 +335,7 @@ exports.applyTo = applyTo; ...@@ -347,6 +335,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instance, options * @param {Function} fn A callback function that is called with instance, options
* @name beforeUpdate * @name beforeUpdate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -354,6 +343,7 @@ exports.applyTo = applyTo; ...@@ -354,6 +343,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instance, options * @param {Function} fn A callback function that is called with instance, options
* @name afterUpdate * @name afterUpdate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -361,6 +351,7 @@ exports.applyTo = applyTo; ...@@ -361,6 +351,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instances, options * @param {Function} fn A callback function that is called with instances, options
* @name beforeBulkCreate * @name beforeBulkCreate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -368,6 +359,7 @@ exports.applyTo = applyTo; ...@@ -368,6 +359,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instances, options * @param {Function} fn A callback function that is called with instances, options
* @name afterBulkCreate * @name afterBulkCreate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -377,6 +369,7 @@ exports.applyTo = applyTo; ...@@ -377,6 +369,7 @@ exports.applyTo = applyTo;
* *
* @name beforeBulkDestroy * @name beforeBulkDestroy
* @alias beforeBulkDelete * @alias beforeBulkDelete
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -386,6 +379,7 @@ exports.applyTo = applyTo; ...@@ -386,6 +379,7 @@ exports.applyTo = applyTo;
* *
* @name afterBulkDestroy * @name afterBulkDestroy
* @alias afterBulkDelete * @alias afterBulkDelete
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -394,6 +388,7 @@ exports.applyTo = applyTo; ...@@ -394,6 +388,7 @@ exports.applyTo = applyTo;
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* *
* @name beforeBulkRestore * @name beforeBulkRestore
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -402,6 +397,7 @@ exports.applyTo = applyTo; ...@@ -402,6 +397,7 @@ exports.applyTo = applyTo;
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* *
* @name afterBulkRestore * @name afterBulkRestore
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -409,6 +405,7 @@ exports.applyTo = applyTo; ...@@ -409,6 +405,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* @name beforeBulkUpdate * @name beforeBulkUpdate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -416,6 +413,7 @@ exports.applyTo = applyTo; ...@@ -416,6 +413,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* @name afterBulkUpdate * @name afterBulkUpdate
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -423,6 +421,7 @@ exports.applyTo = applyTo; ...@@ -423,6 +421,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* @name beforeFind * @name beforeFind
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -430,6 +429,7 @@ exports.applyTo = applyTo; ...@@ -430,6 +429,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* @name beforeFindAfterExpandIncludeAll * @name beforeFindAfterExpandIncludeAll
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -437,6 +437,7 @@ exports.applyTo = applyTo; ...@@ -437,6 +437,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* @name beforeFindAfterOptions * @name beforeFindAfterOptions
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -444,6 +445,7 @@ exports.applyTo = applyTo; ...@@ -444,6 +445,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with instance(s), options * @param {Function} fn A callback function that is called with instance(s), options
* @name afterFind * @name afterFind
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -451,6 +453,7 @@ exports.applyTo = applyTo; ...@@ -451,6 +453,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options * @param {Function} fn A callback function that is called with options
* @name beforeCount * @name beforeCount
* @memberOf Sequelize.Model
*/ */
/** /**
...@@ -458,6 +461,7 @@ exports.applyTo = applyTo; ...@@ -458,6 +461,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with attributes, options * @param {Function} fn A callback function that is called with attributes, options
* @name beforeDefine * @name beforeDefine
* @memberOf Sequelize
*/ */
/** /**
...@@ -465,6 +469,7 @@ exports.applyTo = applyTo; ...@@ -465,6 +469,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with factory * @param {Function} fn A callback function that is called with factory
* @name afterDefine * @name afterDefine
* @memberOf Sequelize
*/ */
/** /**
...@@ -472,6 +477,7 @@ exports.applyTo = applyTo; ...@@ -472,6 +477,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with config, options * @param {Function} fn A callback function that is called with config, options
* @name beforeInit * @name beforeInit
* @memberOf Sequelize
*/ */
/** /**
...@@ -479,6 +485,7 @@ exports.applyTo = applyTo; ...@@ -479,6 +485,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with sequelize * @param {Function} fn A callback function that is called with sequelize
* @name afterInit * @name afterInit
* @memberOf Sequelize
*/ */
/** /**
...@@ -486,6 +493,7 @@ exports.applyTo = applyTo; ...@@ -486,6 +493,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with config passed to connection * @param {Function} fn A callback function that is called with config passed to connection
* @name beforeConnect * @name beforeConnect
* @memberOf Sequelize
*/ */
/** /**
...@@ -493,6 +501,7 @@ exports.applyTo = applyTo; ...@@ -493,6 +501,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync * @param {Function} fn A callback function that is called with options passed to Model.sync
* @name beforeSync * @name beforeSync
* @memberOf Sequelize
*/ */
/** /**
...@@ -500,6 +509,7 @@ exports.applyTo = applyTo; ...@@ -500,6 +509,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync * @param {Function} fn A callback function that is called with options passed to Model.sync
* @name afterSync * @name afterSync
* @memberOf Sequelize
*/ */
/** /**
...@@ -507,6 +517,7 @@ exports.applyTo = applyTo; ...@@ -507,6 +517,7 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options passed to sequelize.sync * @param {Function} fn A callback function that is called with options passed to sequelize.sync
* @name beforeBulkSync * @name beforeBulkSync
* @memberOf Sequelize
*/ */
/** /**
...@@ -514,4 +525,5 @@ exports.applyTo = applyTo; ...@@ -514,4 +525,5 @@ exports.applyTo = applyTo;
* @param {String} name * @param {String} name
* @param {Function} fn A callback function that is called with options passed to sequelize.sync * @param {Function} fn A callback function that is called with options passed to sequelize.sync
* @name afterBulkSync * @name afterBulkSync
* @memberOf Sequelize
*/ */
...@@ -14,6 +14,7 @@ const _ = require('lodash'); ...@@ -14,6 +14,7 @@ const _ = require('lodash');
* @param {Instance} modelInstance The model instance. * @param {Instance} modelInstance The model instance.
* @param {Object} options A dict with options. * @param {Object} options A dict with options.
* @constructor * @constructor
* @private
*/ */
class InstanceValidator { class InstanceValidator {
...@@ -34,6 +35,7 @@ class InstanceValidator { ...@@ -34,6 +35,7 @@ class InstanceValidator {
/** /**
* Exposes a reference to validator.js. This allows you to add custom validations using `validator.extend` * Exposes a reference to validator.js. This allows you to add custom validations using `validator.extend`
* @name validator * @name validator
* @private
*/ */
this.validator = validator; this.validator = validator;
...@@ -42,10 +44,14 @@ class InstanceValidator { ...@@ -42,10 +44,14 @@ class InstanceValidator {
* *
* @type {Array} Will contain keys that correspond to attributes which will * @type {Array} Will contain keys that correspond to attributes which will
* be Arrays of Errors. * be Arrays of Errors.
* @private
*/ */
this.errors = []; this.errors = [];
/** @type {boolean} Indicates if validations are in progress */ /**
* @type {boolean} Indicates if validations are in progress
* @private
*/
this.inProgress = false; this.inProgress = false;
extendModelValidations(modelInstance); extendModelValidations(modelInstance);
...@@ -55,6 +61,7 @@ class InstanceValidator { ...@@ -55,6 +61,7 @@ class InstanceValidator {
* The main entry point for the Validation module, invoke to start the dance. * The main entry point for the Validation module, invoke to start the dance.
* *
* @return {Promise} * @return {Promise}
* @private
*/ */
_validate() { _validate() {
if (this.inProgress) { if (this.inProgress) {
...@@ -79,6 +86,7 @@ class InstanceValidator { ...@@ -79,6 +86,7 @@ class InstanceValidator {
* - On validation failure: Validation Failed Model Hooks * - On validation failure: Validation Failed Model Hooks
* *
* @return {Promise} * @return {Promise}
* @private
*/ */
validate() { validate() {
if (this.options.hooks) { if (this.options.hooks) {
...@@ -344,7 +352,10 @@ class InstanceValidator { ...@@ -344,7 +352,10 @@ class InstanceValidator {
this.errors.push(error); this.errors.push(error);
} }
} }
/** @define {string} The error key for arguments as passed by custom validators */ /**
* @define {string} The error key for arguments as passed by custom validators
* @private
*/
InstanceValidator.RAW_KEY_NAME = '__raw'; InstanceValidator.RAW_KEY_NAME = '__raw';
module.exports = InstanceValidator; module.exports = InstanceValidator;
......
...@@ -40,6 +40,7 @@ class ModelManager { ...@@ -40,6 +40,7 @@ class ModelManager {
* Iterate over Models in an order suitable for e.g. creating tables. Will * Iterate over Models in an order suitable for e.g. creating tables. Will
* take foreign key constraints into account so that dependencies are visited * take foreign key constraints into account so that dependencies are visited
* before dependents. * before dependents.
* @private
*/ */
forEachModel(iterator, options) { forEachModel(iterator, options) {
const models = {}; const models = {};
......
...@@ -31,10 +31,9 @@ const defaultsOptions = { raw: true }; ...@@ -31,10 +31,9 @@ const defaultsOptions = { raw: true };
* However, if getters and/or setters are defined for `field` they will be invoked, instead of returning the value from `dataValues`. * However, if getters and/or setters are defined for `field` they will be invoked, instead of returning the value from `dataValues`.
* Accessing properties directly or using `get` is preferred for regular use, `getDataValue` should only be used for custom getters. * Accessing properties directly or using `get` is preferred for regular use, `getDataValue` should only be used for custom getters.
* *
* @see {Sequelize#define} for more information about getters and setters * @see {@link Sequelize#define} for more information about getters and setters
* @class Model * @class Model
* @mixes Hooks * @mixes Hooks
* @mixes Associations
*/ */
class Model { class Model {
...@@ -608,21 +607,18 @@ class Model { ...@@ -608,21 +607,18 @@ class Model {
* *
* As shown above, column definitions can be either strings, a reference to one of the datatypes that are predefined on the Sequelize constructor, or an object that allows you to specify both the type of the column, and other attributes such as default values, foreign key constraints and custom setters and getters. * As shown above, column definitions can be either strings, a reference to one of the datatypes that are predefined on the Sequelize constructor, or an object that allows you to specify both the type of the column, and other attributes such as default values, foreign key constraints and custom setters and getters.
* *
* For a list of possible data types, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#data-types * For a list of possible data types, see {@link DataTypes}
*
* For more about getters and setters, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#getters-setters
*
* For more about instance and class methods, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#expansion-of-models
* *
* For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations * For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations
* *
* @see {DataTypes} * @see {@link DataTypes}
* @see {Hooks} * @see {@link Hooks}
*
* @param {Object} attributes An object, where each attribute is a column of the table. Each column can be either a DataType, a string or a type-description object, with the properties described below: * @param {Object} attributes An object, where each attribute is a column of the table. Each column can be either a DataType, a string or a type-description object, with the properties described below:
* @param {String|DataType|Object} attributes.column The description of a database column * @param {String|DataTypes|Object} attributes.column The description of a database column
* @param {String|DataType} attributes.column.type A string or a data type * @param {String|DataTypes} attributes.column.type A string or a data type
* @param {Boolean} [attributes.column.allowNull=true] If false, the column will have a NOT NULL constraint, and a not null validation will be run before an instance is saved. * @param {Boolean} [attributes.column.allowNull=true] If false, the column will have a NOT NULL constraint, and a not null validation will be run before an instance is saved.
* @param {Any} [attributes.column.defaultValue=null] A literal default value, a JavaScript function, or an SQL function (see `sequelize.fn`) * @param {any} [attributes.column.defaultValue=null] A literal default value, a JavaScript function, or an SQL function (see `sequelize.fn`)
* @param {String|Boolean} [attributes.column.unique=false] If true, the column will get a unique constraint. If a string is provided, the column will be part of a composite unique index. If multiple columns have the same string, they will be part of the same unique index * @param {String|Boolean} [attributes.column.unique=false] If true, the column will get a unique constraint. If a string is provided, the column will be part of a composite unique index. If multiple columns have the same string, they will be part of the same unique index
* @param {Boolean} [attributes.column.primaryKey=false] * @param {Boolean} [attributes.column.primaryKey=false]
* @param {String} [attributes.column.field=null] If set, sequelize will map the attribute name to a different name in the database * @param {String} [attributes.column.field=null] If set, sequelize will map the attribute name to a different name in the database
...@@ -636,8 +632,7 @@ class Model { ...@@ -636,8 +632,7 @@ class Model {
* @param {Function} [attributes.column.get] Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying values. * @param {Function} [attributes.column.get] Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying values.
* @param {Function} [attributes.column.set] Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the underlying values. * @param {Function} [attributes.column.set] Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the underlying values.
* @param {Object} [attributes.validate] An object of validations to execute for this column every time the model is saved. Can be either the name of a validation provided by validator.js, a validation function provided by extending validator.js (see the `DAOValidator` property for more details), or a custom validation function. Custom validation functions are called with the value of the field, and can possibly take a second callback argument, to signal that they are asynchronous. If the validator is sync, it should throw in the case of a failed validation, it it is async, the callback should be called with the error text. * @param {Object} [attributes.validate] An object of validations to execute for this column every time the model is saved. Can be either the name of a validation provided by validator.js, a validation function provided by extending validator.js (see the `DAOValidator` property for more details), or a custom validation function. Custom validation functions are called with the value of the field, and can possibly take a second callback argument, to signal that they are asynchronous. If the validator is sync, it should throw in the case of a failed validation, it it is async, the callback should be called with the error text.
* @param {Object} options These options are merged with the default define options provided to the Sequelize constructor * @param {Object} [options] These options are merged with the default define options provided to the Sequelize constructor
* @param {Object} options.sequelize The Sequelize connection to use. Required
* @param {Object} [options.defaultScope={}] Define the default search scope to use for this model. Scopes have the same form as the options passed to find / findAll * @param {Object} [options.defaultScope={}] Define the default search scope to use for this model. Scopes have the same form as the options passed to find / findAll
* @param {Object} [options.scopes] More scopes, defined in the same way as defaultScope above. See `Model.scope` for more information about how scopes are defined, and what you can do with them * @param {Object} [options.scopes] More scopes, defined in the same way as defaultScope above. See `Model.scope` for more information about how scopes are defined, and what you can do with them
* @param {Boolean} [options.omitNull] Don't persist null values. This means that all columns with null values will not be saved * @param {Boolean} [options.omitNull] Don't persist null values. This means that all columns with null values will not be saved
...@@ -645,7 +640,7 @@ class Model { ...@@ -645,7 +640,7 @@ class Model {
* @param {Boolean} [options.paranoid=false] Calling `destroy` will not delete the model, but instead set a `deletedAt` timestamp if this is true. Needs `timestamps=true` to work * @param {Boolean} [options.paranoid=false] Calling `destroy` will not delete the model, but instead set a `deletedAt` timestamp if this is true. Needs `timestamps=true` to work
* @param {Boolean} [options.underscored=false] Converts all camelCased columns to underscored if true * @param {Boolean} [options.underscored=false] Converts all camelCased columns to underscored if true
* @param {Boolean} [options.underscoredAll=false] Converts camelCased model names to underscored table names if true * @param {Boolean} [options.underscoredAll=false] Converts camelCased model names to underscored table names if true
* @param {Boolean} [options.freezeTableName=false] If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name. Otherwise, the model name will be pluralized * @param {Boolean} [options.freezeTableName=false] If freezeTableName is true, sequelize will not try to alter the model name to get the table name. Otherwise, the model name will be pluralized
* @param {Object} [options.name] An object with two attributes, `singular` and `plural`, which are used when this model is associated to others. * @param {Object} [options.name] An object with two attributes, `singular` and `plural`, which are used when this model is associated to others.
* @param {String} [options.name.singular=Utils.singularize(modelName)] * @param {String} [options.name.singular=Utils.singularize(modelName)]
* @param {String} [options.name.plural=Utils.pluralize(modelName)] * @param {String} [options.name.plural=Utils.pluralize(modelName)]
...@@ -668,7 +663,7 @@ class Model { ...@@ -668,7 +663,7 @@ class Model {
* @param {String} [options.initialAutoIncrement] Set the initial AUTO_INCREMENT value for the table in MySQL. * @param {String} [options.initialAutoIncrement] Set the initial AUTO_INCREMENT value for the table in MySQL.
* @param {Object} [options.hooks] An object of hook function that are called before and after certain lifecycle events. The possible hooks are: beforeValidate, afterValidate, validationFailed, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook functions and their signatures. Each property can either be a function, or an array of functions. * @param {Object} [options.hooks] An object of hook function that are called before and after certain lifecycle events. The possible hooks are: beforeValidate, afterValidate, validationFailed, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook functions and their signatures. Each property can either be a function, or an array of functions.
* @param {Object} [options.validate] An object of model wide validations. Validations have access to all model values via `this`. If the validator function takes an argument, it is assumed to be async, and is called with a callback that accepts an optional error. * @param {Object} [options.validate] An object of model wide validations. Validations have access to all model values via `this`. If the validator function takes an argument, it is assumed to be async, and is called with a callback that accepts an optional error.
*
* @return {Model} * @return {Model}
*/ */
static init(attributes, options) { // testhint options:none static init(attributes, options) { // testhint options:none
...@@ -1045,7 +1040,7 @@ class Model { ...@@ -1045,7 +1040,7 @@ class Model {
/** /**
* Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this) * Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the model instance (this)
* @see {Sequelize#sync} for options * @see {@link Sequelize#sync} for options
* @return {Promise<this>} * @return {Promise<this>}
*/ */
static sync(options) { static sync(options) {
...@@ -1129,7 +1124,7 @@ class Model { ...@@ -1129,7 +1124,7 @@ class Model {
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. * @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging). * @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* *
* @see {Sequelize#define} for more information about setting a default schema. * @see {@link Sequelize#define} for more information about setting a default schema.
* *
* @return {this} * @return {this}
*/ */
...@@ -1244,7 +1239,7 @@ class Model { ...@@ -1244,7 +1239,7 @@ class Model {
* // WHERE email like 'dan@sequelize.com%' AND access_level >= 42 * // WHERE email like 'dan@sequelize.com%' AND access_level >= 42
* ``` * ```
* *
* @param {Array|Object|String|null} options* The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments. To apply simple scopes and scope functions with no arguments, pass them as strings. For scope function, pass an object, with a `method` property. The value can either be a string, if the method does not take any arguments, or an array, where the first element is the name of the method, and consecutive elements are arguments to that method. Pass null to remove all scopes, including the default. * @param {...Array|Object|String|null} options The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments. To apply simple scopes and scope functions with no arguments, pass them as strings. For scope function, pass an object, with a `method` property. The value can either be a string, if the method does not take any arguments, or an array, where the first element is the name of the method, and consecutive elements are arguments to that method. Pass null to remove all scopes, including the default.
* @return {Model} A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope. * @return {Model} A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope.
*/ */
static scope(option) { static scope(option) {
...@@ -1376,7 +1371,9 @@ class Model { ...@@ -1376,7 +1371,9 @@ class Model {
* WHERE `Model`.`name` = 'a project' AND (`Model`.`id` IN (1, 2, 3) OR (`Model`.`id` > 10 AND `Model`.`id` < 100)); * WHERE `Model`.`name` = 'a project' AND (`Model`.`id` IN (1, 2, 3) OR (`Model`.`id` > 10 AND `Model`.`id` < 100));
* ``` * ```
* *
* The success listener is called with an array of instances if the query succeeds. * The promise is resolved with an array of Model instances if the query succeeds.
*
* __Alias__: _all_
* *
* @param {Object} [options] A hash of options to describe the scope of the search * @param {Object} [options] A hash of options to describe the scope of the search
* @param {Object} [options.where] A hash of attributes to describe your search. See above for examples. * @param {Object} [options.where] A hash of attributes to describe your search. See above for examples.
...@@ -1410,11 +1407,9 @@ class Model { ...@@ -1410,11 +1407,9 @@ class Model {
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) * @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {Boolean|Error} [options.rejectOnEmpty=false] Throws an error when no records found * @param {Boolean|Error} [options.rejectOnEmpty=false] Throws an error when no records found
* *
* @see {Sequelize#query} * @see {@link Sequelize#query}
* @return {Promise<Array<Instance>>} * @return {Promise<Array<Model>>}
* @alias all
*/ */
static findAll(options) { static findAll(options) {
if (options !== undefined && !_.isPlainObject(options)) { if (options !== undefined && !_.isPlainObject(options)) {
throw new Error('The argument passed to findAll must be an options object, use findById if you wish to pass a single primary key value'); throw new Error('The argument passed to findAll must be an options object, use findById if you wish to pass a single primary key value');
...@@ -1554,14 +1549,15 @@ class Model { ...@@ -1554,14 +1549,15 @@ class Model {
/** /**
* Search for a single instance by its primary key. * Search for a single instance by its primary key.
* *
* __Alias__: _findByPrimary_
*
* @param {Number|String|Buffer} id The value of the desired instance's primary key. * @param {Number|String|Buffer} id The value of the desired instance's primary key.
* @param {Object} [options] * @param {Object} [options]
* @param {Transaction} [options.transaction] Transaction to run query under * @param {Transaction} [options.transaction] Transaction to run query under
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) * @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* *
* @see {Model#findAll} for a full explanation of options * @see {@link Model#findAll} for a full explanation of options
* @return {Promise<Instance>} * @return {Promise<Model>}
* @alias findByPrimary
*/ */
static findById(param, options) { static findById(param, options) {
// return Promise resolved with null if no arguments are passed // return Promise resolved with null if no arguments are passed
...@@ -1585,13 +1581,14 @@ class Model { ...@@ -1585,13 +1581,14 @@ class Model {
/** /**
* Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance. * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single instance.
* *
* __Alias__: _find_
*
* @param {Object} [options] A hash of options to describe the scope of the search * @param {Object} [options] A hash of options to describe the scope of the search
* @param {Transaction} [options.transaction] Transaction to run query under * @param {Transaction} [options.transaction] Transaction to run query under
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) * @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* *
* @see {Model#findAll} for an explanation of options * @see {@link Model#findAll} for an explanation of options
* @return {Promise<Instance>} * @return {Promise<Model>}
* @alias find
*/ */
static findOne(options) { static findOne(options) {
if (options !== undefined && !_.isPlainObject(options)) { if (options !== undefined && !_.isPlainObject(options)) {
...@@ -1743,11 +1740,12 @@ class Model { ...@@ -1743,11 +1740,12 @@ class Model {
* ``` * ```
* Because the include for `Profile` has `required` set it will result in an inner join, and only the users who have a profile will be counted. If we remove `required` from the include, both users with and without profiles will be counted * Because the include for `Profile` has `required` set it will result in an inner join, and only the users who have a profile will be counted. If we remove `required` from the include, both users with and without profiles will be counted
* *
* __Alias__: _findAndCountAll_
*
* @param {Object} [findOptions] See findAll * @param {Object} [findOptions] See findAll
* *
* @see {Model#findAll} for a specification of find and query options * @see {@link Model#findAll} for a specification of find and query options
* @return {Promise<Object>} * @return {Promise<{count: Integer, rows: Model[]}>}
* @alias findAndCountAll
*/ */
static findAndCount(options) { static findAndCount(options) {
if (options !== undefined && !_.isPlainObject(options)) { if (options !== undefined && !_.isPlainObject(options)) {
...@@ -1777,7 +1775,7 @@ class Model { ...@@ -1777,7 +1775,7 @@ class Model {
* *
* @param {String} field * @param {String} field
* @param {Object} [options] See aggregate * @param {Object} [options] See aggregate
* @see {Model#aggregate} for options * @see {@link Model#aggregate} for options
* *
* @return {Promise<Any>} * @return {Promise<Any>}
*/ */
...@@ -1790,7 +1788,7 @@ class Model { ...@@ -1790,7 +1788,7 @@ class Model {
* *
* @param {String} field * @param {String} field
* @param {Object} [options] See aggregate * @param {Object} [options] See aggregate
* @see {Model#aggregate} for options * @see {@link Model#aggregate} for options
* *
* @return {Promise<Any>} * @return {Promise<Any>}
*/ */
...@@ -1803,7 +1801,7 @@ class Model { ...@@ -1803,7 +1801,7 @@ class Model {
* *
* @param {String} field * @param {String} field
* @param {Object} [options] See aggregate * @param {Object} [options] See aggregate
* @see {Model#aggregate} for options * @see {@link Model#aggregate} for options
* *
* @return {Promise<Number>} * @return {Promise<Number>}
*/ */
...@@ -1853,8 +1851,8 @@ class Model { ...@@ -1853,8 +1851,8 @@ class Model {
/** /**
* Builds a new model instance and calls save on it. * Builds a new model instance and calls save on it.
* @see {Instance#build} * @see {@link Model#build}
* @see {Instance#save} * @see {@link Model#save}
* *
* @param {Object} values * @param {Object} values
* @param {Object} [options] * @param {Object} [options]
...@@ -1872,7 +1870,7 @@ class Model { ...@@ -1872,7 +1870,7 @@ class Model {
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) * @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* @param {Boolean} [options.returning=true] Return the affected rows (only for postgres) * @param {Boolean} [options.returning=true] Return the affected rows (only for postgres)
* *
* @return {Promise<Instance>} * @return {Promise<Model>}
* *
*/ */
static create(values, options) { static create(values, options) {
...@@ -1891,6 +1889,8 @@ class Model { ...@@ -1891,6 +1889,8 @@ class Model {
* Find a row that matches the query, or build (but don't save) the row if none is found. * Find a row that matches the query, or build (but don't save) the row if none is found.
* The successful result of the promise will be (instance, initialized) - Make sure to use .spread() * The successful result of the promise will be (instance, initialized) - Make sure to use .spread()
* *
* __Alias__: _findOrInitialize_
*
* @param {Object} options * @param {Object} options
* @param {Object} options.where A hash of search attributes. * @param {Object} options.where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if building a new instance * @param {Object} [options.defaults] Default values to use if building a new instance
...@@ -1898,8 +1898,7 @@ class Model { ...@@ -1898,8 +1898,7 @@ class Model {
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. * @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging). * @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* *
* @return {Promise<Instance,initialized>} * @return {Promise<Model,initialized>}
* @alias findOrBuild
*/ */
static findOrBuild(options) { static findOrBuild(options) {
if (!options || !options.where || arguments.length > 1) { if (!options || !options.where || arguments.length > 1) {
...@@ -1939,8 +1938,8 @@ class Model { ...@@ -1939,8 +1938,8 @@ class Model {
* @param {Object} options.where where A hash of search attributes. * @param {Object} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance * @param {Object} [options.defaults] Default values to use if creating a new instance
* @param {Transaction} [options.transaction] Transaction to run query under * @param {Transaction} [options.transaction] Transaction to run query under
* @see {Model#findAll} for a full specification of find and options * @see {@link Model#findAll} for a full specification of find and options
* @return {Promise<Instance,created>} * @return {Promise<Model,created>}
*/ */
static findOrCreate(options) { static findOrCreate(options) {
if (!options || !options.where || arguments.length > 1) { if (!options || !options.where || arguments.length > 1) {
...@@ -2032,8 +2031,8 @@ class Model { ...@@ -2032,8 +2031,8 @@ class Model {
* @param {Object} options * @param {Object} options
* @param {Object} options.where where A hash of search attributes. * @param {Object} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance * @param {Object} [options.defaults] Default values to use if creating a new instance
* @see {Model#findAll} for a full specification of find and options * @see {@link Model#findAll} for a full specification of find and options
* @return {Promise<Instance,created>} * @return {Promise<Model,created>}
*/ */
static findCreateFind(options) { static findCreateFind(options) {
if (!options || !options.where) { if (!options || !options.where) {
...@@ -2068,6 +2067,8 @@ class Model { ...@@ -2068,6 +2067,8 @@ class Model {
* *
* **Note** that SQLite returns undefined for created, no matter if the row was created or updated. This is because SQLite always runs INSERT OR IGNORE + UPDATE, in a single query, so there is no way to know whether the row was inserted or not. * **Note** that SQLite returns undefined for created, no matter if the row was created or updated. This is because SQLite always runs INSERT OR IGNORE + UPDATE, in a single query, so there is no way to know whether the row was inserted or not.
* *
* __Alias__: _insertOrUpdate_
*
* @param {Object} values * @param {Object} values
* @param {Object} [options] * @param {Object} [options]
* @param {Boolean} [options.validate=true] Run validations before the row is inserted * @param {Boolean} [options.validate=true] Run validations before the row is inserted
...@@ -2078,7 +2079,6 @@ class Model { ...@@ -2078,7 +2079,6 @@ class Model {
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging). * @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) * @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
* *
* @alias insertOrUpdate
* @return {Promise<created>} Returns a boolean indicating whether the row was created or updated. * @return {Promise<created>} Returns a boolean indicating whether the row was created or updated.
*/ */
static upsert(values, options) { static upsert(values, options) {
...@@ -2308,7 +2308,7 @@ class Model { ...@@ -2308,7 +2308,7 @@ class Model {
* *
* @return {Promise} * @return {Promise}
* *
* @see {Model#destroy} for more information * @see {@link Model#destroy} for more information
*/ */
static truncate(options) { static truncate(options) {
options = Utils.cloneDeep(options) || {}; options = Utils.cloneDeep(options) || {};
...@@ -2795,7 +2795,7 @@ class Model { ...@@ -2795,7 +2795,7 @@ class Model {
/** /**
* Returns the Model the instance was created from. * Returns the Model the instance was created from.
* @see {Model} * @see {@link Model}
* @property Model * @property Model
* @return {Model} * @return {Model}
*/ */
...@@ -2856,7 +2856,7 @@ class Model { ...@@ -2856,7 +2856,7 @@ class Model {
/** /**
* A reference to the sequelize instance * A reference to the sequelize instance
* @see {Sequelize} * @see {@link Sequelize}
* @property sequelize * @property sequelize
* @return {Sequelize} * @return {Sequelize}
*/ */
...@@ -2984,13 +2984,12 @@ class Model { ...@@ -2984,13 +2984,12 @@ class Model {
* *
* If called with a dot.separated key on a JSON/JSONB attribute it will set the value nested and flag the entire object as changed. * If called with a dot.separated key on a JSON/JSONB attribute it will set the value nested and flag the entire object as changed.
* *
* @see {Model#find} for more information about includes * @see {@link Model#findAll} for more information about includes
* @param {String|Object} key * @param {String|Object} key
* @param {any} value * @param {any} value
* @param {Object} [options] * @param {Object} [options]
* @param {Boolean} [options.raw=false] If set to true, field and virtual setters will be ignored * @param {Boolean} [options.raw=false] If set to true, field and virtual setters will be ignored
* @param {Boolean} [options.reset=false] Clear all previously set data values * @param {Boolean} [options.reset=false] Clear all previously set data values
* @alias setAttributes
*/ */
set(key, value, options) { // testhint options:none set(key, value, options) { // testhint options:none
let values; let values;
...@@ -3452,14 +3451,15 @@ class Model { ...@@ -3452,14 +3451,15 @@ class Model {
}); });
} }
/* /**
* Refresh the current instance in-place, i.e. update the object with current data from the DB and return the same object. * Refresh the current instance in-place, i.e. update the object with current data from the DB and return the same object.
* This is different from doing a `find(Instance.id)`, because that would create and return a new instance. With this method, * This is different from doing a `find(Instance.id)`, because that would create and return a new instance. With this method,
* all references to the Instance are updated with the new data and no new objects are created. * all references to the Instance are updated with the new data and no new objects are created.
* *
* @see {Model#find} * @see {@link Model#findAll}
* @param {Object} [options] Options that are passed on to `Model.find` * @param {Object} [options] Options that are passed on to `Model.find`
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. * @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
*
* @return {Promise<this>} * @return {Promise<this>}
*/ */
reload(options) { reload(options) {
...@@ -3488,15 +3488,14 @@ class Model { ...@@ -3488,15 +3488,14 @@ class Model {
}); });
} }
/* /**
* Validate the attribute of this instance according to validation rules set in the model definition. * Validate the attributes of this instance according to validation rules set in the model definition.
* *
* Emits null if and only if validation successful; otherwise an Error instance containing { field name : [error msgs] } entries. * Emits null if and only if validation successful; otherwise an Error instance containing { field name : [error msgs] } entries.
* *
* @param {Object} [options] Options that are passed to the validator * @param {Object} [options] Options that are passed to the validator
* @param {Array} [options.skip] An array of strings. All properties that are in this array will not be validated * @param {Array} [options.skip] An array of strings. All properties that are in this array will not be validated
* @param {Boolean} [options.hooks=true] Run before and after validate hooks * @param {Boolean} [options.hooks=true] Run before and after validate hooks
* @see {InstanceValidator}
* *
* @return {Promise<undefined|Errors.ValidationError>} * @return {Promise<undefined|Errors.ValidationError>}
*/ */
...@@ -3508,13 +3507,12 @@ class Model { ...@@ -3508,13 +3507,12 @@ class Model {
* This is the same as calling `set` and then calling `save` but it only saves the * This is the same as calling `set` and then calling `save` but it only saves the
* exact values passed to it, making it more atomic and safer. * exact values passed to it, making it more atomic and safer.
* *
* @see {Instance#set} * @see {@link Model#set}
* @see {Instance#save} * @see {@link Model#save}
* @param {Object} updates See `set` * @param {Object} updates See `set`
* @param {Object} options See `save` * @param {Object} options See `save`
* *
* @return {Promise<this>} * @return {Promise<this>}
* @alias updateAttributes
*/ */
update(values, options) { update(values, options) {
const changedBefore = this.changed() || []; const changedBefore = this.changed() || [];
...@@ -3638,7 +3636,7 @@ class Model { ...@@ -3638,7 +3636,7 @@ class Model {
* // `by` is ignored, since each column has its own value * // `by` is ignored, since each column has its own value
* ``` * ```
* *
* @see {Instance#reload} * @see {@link Model#reload}
* @param {String|Array|Object} fields If a string is provided, that column is incremented by the value of `by` given in options. If an array is provided, the same is true for each column. If and object is provided, each column is incremented by the value given. * @param {String|Array|Object} fields If a string is provided, that column is incremented by the value of `by` given in options. If an array is provided, the same is true for each column. If and object is provided, each column is incremented by the value given.
* @param {Object} [options] * @param {Object} [options]
* @param {Integer} [options.by=1] The number to increment by * @param {Integer} [options.by=1] The number to increment by
...@@ -3700,7 +3698,7 @@ class Model { ...@@ -3700,7 +3698,7 @@ class Model {
* // `by` is ignored, since each column has its own value * // `by` is ignored, since each column has its own value
* ``` * ```
* *
* @see {Instance#reload} * @see {@link Model#reload}
* @param {String|Array|Object} fields If a string is provided, that column is decremented by the value of `by` given in options. If an array is provided, the same is true for each column. If and object is provided, each column is decremented by the value given * @param {String|Array|Object} fields If a string is provided, that column is decremented by the value of `by` given in options. If an array is provided, the same is true for each column. If and object is provided, each column is decremented by the value given
* @param {Object} [options] * @param {Object} [options]
* @param {Integer} [options.by=1] The number to decrement by * @param {Integer} [options.by=1] The number to decrement by
...@@ -3729,7 +3727,7 @@ class Model { ...@@ -3729,7 +3727,7 @@ class Model {
/** /**
* Check whether this and `other` Instance refer to the same row * Check whether this and `other` Instance refer to the same row
* *
* @param {Instance} other * @param {Model} other
* @return {Boolean} * @return {Boolean}
*/ */
equals(other) { equals(other) {
...@@ -3762,7 +3760,7 @@ class Model { ...@@ -3762,7 +3760,7 @@ class Model {
/** /**
* Convert the instance to a JSON representation. Proxies to calling `get` with no keys. This means get all values gotten from the DB, and apply all custom getters. * Convert the instance to a JSON representation. Proxies to calling `get` with no keys. This means get all values gotten from the DB, and apply all custom getters.
* *
* @see {Instance#get} * @see {@link Model#get}
* @return {object} * @return {object}
*/ */
toJSON() { toJSON() {
......
...@@ -13,6 +13,7 @@ const QueryTypes = require('./query-types'); ...@@ -13,6 +13,7 @@ const QueryTypes = require('./query-types');
/** /**
* The interface that Sequelize uses to talk to all databases * The interface that Sequelize uses to talk to all databases
* @class QueryInterface * @class QueryInterface
* @private
*/ */
class QueryInterface { class QueryInterface {
constructor(sequelize) { constructor(sequelize) {
...@@ -765,6 +766,7 @@ class QueryInterface { ...@@ -765,6 +766,7 @@ class QueryInterface {
* Escape an identifier (e.g. a table or attribute name). If force is true, * Escape an identifier (e.g. a table or attribute name). If force is true,
* the identifier will be quoted even if the `quoteIdentifiers` option is * the identifier will be quoted even if the `quoteIdentifiers` option is
* false. * false.
* @private
*/ */
quoteIdentifier(identifier, force) { quoteIdentifier(identifier, force) {
return this.QueryGenerator.quoteIdentifier(identifier, force); return this.QueryGenerator.quoteIdentifier(identifier, force);
...@@ -778,6 +780,7 @@ class QueryInterface { ...@@ -778,6 +780,7 @@ class QueryInterface {
* Split an identifier into .-separated tokens and quote each part. * Split an identifier into .-separated tokens and quote each part.
* If force is true, the identifier will be quoted even if the * If force is true, the identifier will be quoted even if the
* `quoteIdentifiers` option is false. * `quoteIdentifiers` option is false.
* @private
*/ */
quoteIdentifiers(identifiers, force) { quoteIdentifiers(identifiers, force) {
return this.QueryGenerator.quoteIdentifiers(identifiers, force); return this.QueryGenerator.quoteIdentifiers(identifiers, force);
...@@ -785,6 +788,7 @@ class QueryInterface { ...@@ -785,6 +788,7 @@ class QueryInterface {
/** /**
* Escape a value (e.g. a string, number or date) * Escape a value (e.g. a string, number or date)
* @private
*/ */
escape(value) { escape(value) {
return this.QueryGenerator.escape(value); return this.QueryGenerator.escape(value);
......
'use strict'; 'use strict';
/**
* @namespace QueryTypes
* @memberof Sequelize
*
*
* @property SELECT
* @property INSERT
* @property UPDATE
* @property BULKUPDATE
* @property BULKDELETE
* @property DELETE
* @property UPSERT
* @property VERSION
* @property SHOWTABLES
* @property SHOWINDEXES
* @property DESCRIBE
* @property RAW
* @property FOREIGNKEYS
*/
module.exports = { module.exports = {
SELECT: 'SELECT', SELECT: 'SELECT',
INSERT: 'INSERT', INSERT: 'INSERT',
......
...@@ -244,7 +244,6 @@ class Sequelize { ...@@ -244,7 +244,6 @@ class Sequelize {
/** /**
* Models are stored here under the name given to `sequelize.define` * Models are stored here under the name given to `sequelize.define`
* @property models
*/ */
this.models = {}; this.models = {};
this.modelManager = new ModelManager(this); this.modelManager = new ModelManager(this);
...@@ -287,9 +286,8 @@ class Sequelize { ...@@ -287,9 +286,8 @@ class Sequelize {
* Returns an instance of QueryInterface. * Returns an instance of QueryInterface.
* @method getQueryInterface * @method getQueryInterface
* @memberOf Sequelize
* @return {QueryInterface} An instance (singleton) of QueryInterface. * @return {QueryInterface} An instance (singleton) of QueryInterface.
*
* @see {QueryInterface}
*/ */
getQueryInterface() { getQueryInterface() {
this.queryInterface = this.queryInterface || new QueryInterface(this); this.queryInterface = this.queryInterface || new QueryInterface(this);
...@@ -334,8 +332,8 @@ class Sequelize { ...@@ -334,8 +332,8 @@ class Sequelize {
* *
* For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations * For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations
* *
* @see {DataTypes} * @see {@link DataTypes}
* @see {Hooks} * @param {String} modelName The name of the model. The model will be stored in `sequelize.models` under this name
* @param {String} modelName The name of the model. The model will be stored in `sequelize.models` under this name * @param {String} modelName The name of the model. The model will be stored in `sequelize.models` under this name
* @param {Object} attributes An object, where each attribute is a column of the table. See Model.init() * @param {Object} attributes An object, where each attribute is a column of the table. See Model.init()
* @param {Object} [options] These options are merged with the default define options provided to the Sequelize constructor and passed to Model.init() * @param {Object} [options] These options are merged with the default define options provided to the Sequelize constructor and passed to Model.init()
...@@ -352,6 +350,7 @@ class Sequelize { ...@@ -352,6 +350,7 @@ class Sequelize {
model.init(attributes, options); model.init(attributes, options);
return model; return model;
} }
...@@ -452,8 +451,9 @@ class Sequelize { ...@@ -452,8 +451,9 @@ class Sequelize {
* @param {Object} [options.fieldMap] Map returned fields to arbitrary names for `SELECT` query type. * @param {Object} [options.fieldMap] Map returned fields to arbitrary names for `SELECT` query type.
* *
* @return {Promise} * @return {Promise}
* @memberof Sequelize
* *
* @see {Model#build} for more information about instance option. * @see {@link Model#build} for more information about instance option.
*/ */
query(sql, options) { query(sql, options) {
if (arguments.length > 2) { if (arguments.length > 2) {
...@@ -582,6 +582,7 @@ class Sequelize { ...@@ -582,6 +582,7 @@ class Sequelize {
* @param {Object} options Query options. * @param {Object} options Query options.
* @param {Transaction} options.transaction The transaction that the query should be executed under * @param {Transaction} options.transaction The transaction that the query should be executed under
* *
* @memberof Sequelize
* @return {Promise} * @return {Promise}
*/ */
set(variables, options) { set(variables, options) {
...@@ -622,10 +623,10 @@ class Sequelize { ...@@ -622,10 +623,10 @@ class Sequelize {
/** /**
* Create a new database schema. * Create a new database schema.
* *
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), * Note, that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this command will do nothing. * not a database table. In mysql and sqlite, this command will do nothing.
* *
* @see {Model#schema} * @see {@link Model#schema}
* @param {String} schema Name of the schema * @param {String} schema Name of the schema
* @param {Object} options={} * @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging * @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
...@@ -638,7 +639,7 @@ class Sequelize { ...@@ -638,7 +639,7 @@ class Sequelize {
/** /**
* Show all defined schemas * Show all defined schemas
* *
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), * Note, that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this will show all tables. * not a database table. In mysql and sqlite, this will show all tables.
* @param {Object} options={} * @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging * @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
...@@ -651,7 +652,7 @@ class Sequelize { ...@@ -651,7 +652,7 @@ class Sequelize {
/** /**
* Drop a single schema * Drop a single schema
* *
* Note,that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html), * Note, that this is a schema in the [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
* not a database table. In mysql and sqlite, this drop a table matching the schema name * not a database table. In mysql and sqlite, this drop a table matching the schema name
* @param {String} schema Name of the schema * @param {String} schema Name of the schema
* @param {Object} options={} * @param {Object} options={}
...@@ -679,8 +680,8 @@ class Sequelize { ...@@ -679,8 +680,8 @@ class Sequelize {
* Sync all defined models to the DB. * Sync all defined models to the DB.
* *
* @param {Object} [options={}] * @param {Object} [options={}]
* @param {Boolean} [options.force=false] If force is true, each DAO will do DROP TABLE IF EXISTS ..., before it tries to create its own table * @param {Boolean} [options.force=false] If force is true, each Model will run `DROP TABLE IF EXISTS`, before it tries to create its own table
* @param {RegEx} [options.match] Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code * @param {RegExp} [options.match] Match a regex against the database name before syncing, a safety check for cases where force: true is used in tests but not live code
* @param {Boolean|function} [options.logging=console.log] A function that logs sql queries, or false for no logging * @param {Boolean|function} [options.logging=console.log] A function that logs sql queries, or false for no logging
* @param {String} [options.schema='public'] The schema that the tables should be created in. This can be overriden for each table in sequelize.define * @param {String} [options.schema='public'] The schema that the tables should be created in. This can be overriden for each table in sequelize.define
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) * @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
...@@ -737,7 +738,7 @@ class Sequelize { ...@@ -737,7 +738,7 @@ class Sequelize {
* @param {Boolean|function} [options.logging] A function that logs sql queries, or false for no logging * @param {Boolean|function} [options.logging] A function that logs sql queries, or false for no logging
* @return {Promise} * @return {Promise}
* *
* @see {Model#truncate} for more information * @see {@link Model#truncate} for more information
*/ */
truncate(options) { truncate(options) {
const models = []; const models = [];
...@@ -759,7 +760,7 @@ class Sequelize { ...@@ -759,7 +760,7 @@ class Sequelize {
/** /**
* Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model * Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model
* @see {Model#drop} for options * @see {@link Model#drop} for options
* *
* @param {object} options The options passed to each call to Model.drop * @param {object} options The options passed to each call to Model.drop
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging * @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
...@@ -780,9 +781,7 @@ class Sequelize { ...@@ -780,9 +781,7 @@ class Sequelize {
/** /**
* Test the connection by trying to authenticate * Test the connection by trying to authenticate
* *
* @fires success If authentication was successful
* @error 'Invalid credentials' if the authentication failed (even if the database did not respond at all...) * @error 'Invalid credentials' if the authentication failed (even if the database did not respond at all...)
* @alias validate
* @return {Promise} * @return {Promise}
*/ */
authenticate(options) { authenticate(options) {
...@@ -804,16 +803,16 @@ class Sequelize { ...@@ -804,16 +803,16 @@ class Sequelize {
* }) * })
* ``` * ```
* *
* @see {Model#find} * @see {@link Model#findAll}
* @see {Model#findAll} * @see {@link Model#define}
* @see {Model#define} * @see {@link Sequelize#col}
* @see {Sequelize#col}
* @method fn * @method fn
* *
* @param {String} fn The function you want to call * @param {String} fn The function you want to call
* @param {any} args All further arguments will be passed as arguments to the function * @param {any} args All further arguments will be passed as arguments to the function
* *
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.fn} * @return {Sequelize.fn}
*/ */
static fn(fn) { static fn(fn) {
...@@ -822,11 +821,12 @@ class Sequelize { ...@@ -822,11 +821,12 @@ class Sequelize {
/** /**
* Creates a object representing a column in the DB. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped. * Creates a object representing a column in the DB. This is often useful in conjunction with `sequelize.fn`, since raw string arguments to fn will be escaped.
* @see {Sequelize#fn} * @see {@link Sequelize#fn}
* *
* @method col * @method col
* @param {String} col The name of the column * @param {String} col The name of the column
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.col} * @return {Sequelize.col}
*/ */
static col(col) { static col(col) {
...@@ -840,6 +840,7 @@ class Sequelize { ...@@ -840,6 +840,7 @@ class Sequelize {
* @param {any} val The value to cast * @param {any} val The value to cast
* @param {String} type The type to cast it to * @param {String} type The type to cast it to
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.cast} * @return {Sequelize.cast}
*/ */
static cast(val, type) { static cast(val, type) {
...@@ -853,6 +854,7 @@ class Sequelize { ...@@ -853,6 +854,7 @@ class Sequelize {
* @param {any} val * @param {any} val
* @alias asIs * @alias asIs
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.literal} * @return {Sequelize.literal}
*/ */
static literal(val) { static literal(val) {
...@@ -861,11 +863,12 @@ class Sequelize { ...@@ -861,11 +863,12 @@ class Sequelize {
/** /**
* An AND query * An AND query
* @see {Model#find} * @see {@link Model#findAll}
* *
* @method and * @method and
* @param {String|Object} args Each argument will be joined by AND * @param {String|Object} args Each argument will be joined by AND
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.and} * @return {Sequelize.and}
*/ */
static and() { static and() {
...@@ -874,11 +877,12 @@ class Sequelize { ...@@ -874,11 +877,12 @@ class Sequelize {
/** /**
* An OR query * An OR query
* @see {Model#find} * @see {@link Model#findAll}
* *
* @method or * @method or
* @param {String|Object} args Each argument will be joined by OR * @param {String|Object} args Each argument will be joined by OR
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.or} * @return {Sequelize.or}
*/ */
static or() { static or() {
...@@ -887,11 +891,12 @@ class Sequelize { ...@@ -887,11 +891,12 @@ class Sequelize {
/** /**
* Creates an object representing nested where conditions for postgres's json data-type. * Creates an object representing nested where conditions for postgres's json data-type.
* @see {Model#find} * @see {@link Model#findAll}
* *
* @method json * @method json
* @param {String|Object} conditions A hash containing strings/numbers or other nested hash, a string using dot notation or a string using postgres json syntax. * @param {String|Object} conditions A hash containing strings/numbers or other nested hash, a string using dot notation or a string using postgres json syntax.
* @param {String|Number|Boolean} [value] An optional value to compare against. Produces a string of the form "<json path> = '<value>'". * @param {String|Number|Boolean} [value] An optional value to compare against. Produces a string of the form "<json path> = '<value>'".
* @memberof Sequelize
* @return {Sequelize.json} * @return {Sequelize.json}
*/ */
static json(conditionsOrPath, value) { static json(conditionsOrPath, value) {
...@@ -906,7 +911,7 @@ class Sequelize { ...@@ -906,7 +911,7 @@ class Sequelize {
* *
* For string attributes, use the regular `{ where: { attr: something }}` syntax. If you don't want your string to be escaped, use `sequelize.literal`. * For string attributes, use the regular `{ where: { attr: something }}` syntax. If you don't want your string to be escaped, use `sequelize.literal`.
* *
* @see {Model#find} * @see {@link Model#findAll}
* *
* @param {Object} attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the POJO syntax * @param {Object} attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the POJO syntax
* @param {string} [comparator='='] * @param {string} [comparator='=']
...@@ -914,6 +919,7 @@ class Sequelize { ...@@ -914,6 +919,7 @@ class Sequelize {
* @method where * @method where
* @alias condition * @alias condition
* @since v2.0.0-dev3 * @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.where} * @return {Sequelize.where}
*/ */
static where(attr, comparator, logic) { static where(attr, comparator, logic) {
...@@ -957,15 +963,14 @@ class Sequelize { ...@@ -957,15 +963,14 @@ class Sequelize {
* ``` * ```
* Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace * Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace
* *
* @see {Transaction} * @see {@link Transaction}
* @param {Object} [options={}] * @param {Object} [options={}]
* @param {Boolean} [options.autocommit] * @param {Boolean} [options.autocommit]
* @param {String} [options.type='DEFERRED'] See `Sequelize.Transaction.TYPES` for possible options. Sqlite only. * @param {String} [options.type='DEFERRED'] See `Sequelize.Transaction.TYPES` for possible options. Sqlite only.
* @param {String} [options.isolationLevel] See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options * @param {String} [options.isolationLevel] See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. * @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
* @param {Function} [autoCallback] The callback is called with the transaction object, and should return a promise. If the promise is resolved, the transaction commits; if the promise rejects, the transaction rolls back
* @return {Promise} * @return {Promise}
* @fires error If there is an uncaught error during the transaction
* @fires success When the transaction has ended (either committed or rolled back)
*/ */
transaction(options, autoCallback) { transaction(options, autoCallback) {
if (typeof options === 'function') { if (typeof options === 'function') {
...@@ -1148,7 +1153,6 @@ Sequelize.prototype.validate = Sequelize.prototype.authenticate; ...@@ -1148,7 +1153,6 @@ Sequelize.prototype.validate = Sequelize.prototype.authenticate;
/** /**
* Sequelize version number. * Sequelize version number.
* @property version
*/ */
Sequelize.version = require('../package.json').version; Sequelize.version = require('../package.json').version;
...@@ -1156,8 +1160,7 @@ Sequelize.options = {hooks: {}}; ...@@ -1156,8 +1160,7 @@ Sequelize.options = {hooks: {}};
/** /**
* A reference to Sequelize constructor from sequelize. Useful for accessing DataTypes, Errors etc. * A reference to Sequelize constructor from sequelize. Useful for accessing DataTypes, Errors etc.
* @property Sequelize * @see {@link Sequelize}
* @see {Sequelize}
*/ */
Sequelize.prototype.Sequelize = Sequelize; Sequelize.prototype.Sequelize = Sequelize;
...@@ -1168,19 +1171,17 @@ Sequelize.prototype.Utils = Sequelize.Utils = Utils; ...@@ -1168,19 +1171,17 @@ Sequelize.prototype.Utils = Sequelize.Utils = Utils;
/** /**
* A handy reference to the bluebird Promise class * A handy reference to the bluebird Promise class
* @property Promise
*/ */
Sequelize.prototype.Promise = Sequelize.Promise = Promise; Sequelize.prototype.Promise = Sequelize.Promise = Promise;
/** /**
* Available query types for use with `sequelize.query` * Available query types for use with `sequelize.query`
* @property QueryTypes * @see {@link Sequelize.QueryTypes}
*/ */
Sequelize.prototype.QueryTypes = Sequelize.QueryTypes = QueryTypes; Sequelize.prototype.QueryTypes = Sequelize.QueryTypes = QueryTypes;
/** /**
* Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor. * Exposes the validator.js object, so you can extend it with custom validation functions. The validator is exposed both on the instance, and on the constructor.
* @property Validator
* @see https://github.com/chriso/validator.js * @see https://github.com/chriso/validator.js
*/ */
Sequelize.prototype.Validator = Sequelize.Validator = Validator; Sequelize.prototype.Validator = Sequelize.Validator = Validator;
...@@ -1194,24 +1195,21 @@ for (const dataType in DataTypes) { ...@@ -1194,24 +1195,21 @@ for (const dataType in DataTypes) {
/** /**
* A reference to the sequelize transaction class. Use this to access isolationLevels and types when creating a transaction * A reference to the sequelize transaction class. Use this to access isolationLevels and types when creating a transaction
* @property Transaction * @see {@link Transaction}
* @see {Transaction} * @see {@link Sequelize.transaction}
* @see {Sequelize#transaction}
*/ */
Sequelize.prototype.Transaction = Sequelize.Transaction = Transaction; Sequelize.prototype.Transaction = Sequelize.Transaction = Transaction;
/** /**
* A reference to the deferrable collection. Use this to access the different deferrable options. * A reference to the deferrable collection. Use this to access the different deferrable options.
* @property Deferrable * @see {@link Transaction.Deferrable}
* @see {Deferrable} * @see {@link Sequelize#transaction}
* @see {Sequelize#transaction}
*/ */
Sequelize.prototype.Deferrable = Sequelize.Deferrable = Deferrable; Sequelize.prototype.Deferrable = Sequelize.Deferrable = Deferrable;
/** /**
* A reference to the sequelize association class. * A reference to the sequelize association class.
* @property Association * @see {@link Association}
* @see {Association}
*/ */
Sequelize.prototype.Association = Sequelize.Association = Association; Sequelize.prototype.Association = Sequelize.Association = Association;
...@@ -1228,125 +1226,54 @@ Sequelize.useInflection = Utils.useInflection; ...@@ -1228,125 +1226,54 @@ Sequelize.useInflection = Utils.useInflection;
Hooks.applyTo(Sequelize); Hooks.applyTo(Sequelize);
Hooks.applyTo(Sequelize.prototype); Hooks.applyTo(Sequelize.prototype);
/**
* A general error class
* @property Error
* @see {Errors#BaseError}
*/
Sequelize.prototype.Error = Sequelize.Error = Sequelize.prototype.Error = Sequelize.Error =
sequelizeErrors.BaseError; sequelizeErrors.BaseError;
/**
* Emitted when a validation fails
* @property ValidationError
* @see {Errors#ValidationError}
*/
Sequelize.prototype.ValidationError = Sequelize.ValidationError = Sequelize.prototype.ValidationError = Sequelize.ValidationError =
sequelizeErrors.ValidationError; sequelizeErrors.ValidationError;
/**
* Describes a validation error on an instance path
* @property ValidationErrorItem
* @see {Errors#ValidationErrorItem}
*/
Sequelize.prototype.ValidationErrorItem = Sequelize.ValidationErrorItem = Sequelize.prototype.ValidationErrorItem = Sequelize.ValidationErrorItem =
sequelizeErrors.ValidationErrorItem; sequelizeErrors.ValidationErrorItem;
/**
* A base class for all database related errors.
* @see {Errors#DatabaseError}
*/
Sequelize.prototype.DatabaseError = Sequelize.DatabaseError = Sequelize.prototype.DatabaseError = Sequelize.DatabaseError =
sequelizeErrors.DatabaseError; sequelizeErrors.DatabaseError;
/**
* Thrown when a database query times out because of a deadlock
* @see {Errors#TimeoutError}
*/
Sequelize.prototype.TimeoutError = Sequelize.TimeoutError = Sequelize.prototype.TimeoutError = Sequelize.TimeoutError =
sequelizeErrors.TimeoutError; sequelizeErrors.TimeoutError;
/**
* Thrown when a unique constraint is violated in the database
* @see {Errors#UniqueConstraintError}
*/
Sequelize.prototype.UniqueConstraintError = Sequelize.UniqueConstraintError = Sequelize.prototype.UniqueConstraintError = Sequelize.UniqueConstraintError =
sequelizeErrors.UniqueConstraintError; sequelizeErrors.UniqueConstraintError;
/**
* Thrown when an exclusion constraint is violated in the database
* @see {Errors#ExclusionConstraintError}
*/
Sequelize.prototype.ExclusionConstraintError = Sequelize.ExclusionConstraintError = Sequelize.prototype.ExclusionConstraintError = Sequelize.ExclusionConstraintError =
sequelizeErrors.ExclusionConstraintError; sequelizeErrors.ExclusionConstraintError;
/**
* Thrown when a foreign key constraint is violated in the database
* @see {Errors#ForeignKeyConstraintError}
*/
Sequelize.prototype.ForeignKeyConstraintError = Sequelize.ForeignKeyConstraintError = Sequelize.prototype.ForeignKeyConstraintError = Sequelize.ForeignKeyConstraintError =
sequelizeErrors.ForeignKeyConstraintError; sequelizeErrors.ForeignKeyConstraintError;
/**
* A base class for all connection related errors.
* @see {Errors#ConnectionError}
*/
Sequelize.prototype.ConnectionError = Sequelize.ConnectionError = Sequelize.prototype.ConnectionError = Sequelize.ConnectionError =
sequelizeErrors.ConnectionError; sequelizeErrors.ConnectionError;
/**
* Thrown when a connection to a database is refused
* @see {Errors#ConnectionRefusedError}
*/
Sequelize.prototype.ConnectionRefusedError = Sequelize.ConnectionRefusedError = Sequelize.prototype.ConnectionRefusedError = Sequelize.ConnectionRefusedError =
sequelizeErrors.ConnectionRefusedError; sequelizeErrors.ConnectionRefusedError;
/**
* Thrown when a connection to a database is refused due to insufficient access
* @see {Errors#AccessDeniedError}
*/
Sequelize.prototype.AccessDeniedError = Sequelize.AccessDeniedError = Sequelize.prototype.AccessDeniedError = Sequelize.AccessDeniedError =
sequelizeErrors.AccessDeniedError; sequelizeErrors.AccessDeniedError;
/**
* Thrown when a connection to a database has a hostname that was not found
* @see {Errors#HostNotFoundError}
*/
Sequelize.prototype.HostNotFoundError = Sequelize.HostNotFoundError = Sequelize.prototype.HostNotFoundError = Sequelize.HostNotFoundError =
sequelizeErrors.HostNotFoundError; sequelizeErrors.HostNotFoundError;
/**
* Thrown when a connection to a database has a hostname that was not reachable
* @see {Errors#HostNotReachableError}
*/
Sequelize.prototype.HostNotReachableError = Sequelize.HostNotReachableError = Sequelize.prototype.HostNotReachableError = Sequelize.HostNotReachableError =
sequelizeErrors.HostNotReachableError; sequelizeErrors.HostNotReachableError;
/**
* Thrown when a connection to a database has invalid values for any of the connection parameters
* @see {Errors#InvalidConnectionError}
*/
Sequelize.prototype.InvalidConnectionError = Sequelize.InvalidConnectionError = Sequelize.prototype.InvalidConnectionError = Sequelize.InvalidConnectionError =
sequelizeErrors.InvalidConnectionError; sequelizeErrors.InvalidConnectionError;
/**
* Thrown when a connection to a database times out
* @see {Errors#ConnectionTimedOutError}
*/
Sequelize.prototype.ConnectionTimedOutError = Sequelize.ConnectionTimedOutError = Sequelize.prototype.ConnectionTimedOutError = Sequelize.ConnectionTimedOutError =
sequelizeErrors.ConnectionTimedOutError; sequelizeErrors.ConnectionTimedOutError;
/**
* Thrown when a some problem occurred with Instance methods (see message for details)
* @see {Errors#InstanceError}
*/
Sequelize.prototype.InstanceError = Sequelize.InstanceError = Sequelize.prototype.InstanceError = Sequelize.InstanceError =
sequelizeErrors.InstanceError; sequelizeErrors.InstanceError;
/**
* Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details)
* @see {Errors#RecordNotFoundError}
*/
Sequelize.prototype.EmptyResultError = Sequelize.EmptyResultError = Sequelize.prototype.EmptyResultError = Sequelize.EmptyResultError =
sequelizeErrors.EmptyResultError; sequelizeErrors.EmptyResultError;
......
...@@ -16,6 +16,8 @@ const uuid = require('node-uuid'); ...@@ -16,6 +16,8 @@ const uuid = require('node-uuid');
* @param {String} options.type=true Sets the type of the transaction. * @param {String} options.type=true Sets the type of the transaction.
* @param {String} options.isolationLevel=true Sets the isolation level of the transaction. * @param {String} options.isolationLevel=true Sets the isolation level of the transaction.
* @param {String} options.deferrable Sets the constraints to be deferred or immediately checked. * @param {String} options.deferrable Sets the constraints to be deferred or immediately checked.
*
* @see {@link Sequelize.transaction}
*/ */
class Transaction { class Transaction {
constructor(sequelize, options) { constructor(sequelize, options) {
...@@ -170,20 +172,10 @@ class Transaction { ...@@ -170,20 +172,10 @@ class Transaction {
* Default to `DEFERRED` but you can override the default type by passing `options.transactionType` in `new Sequelize`. * Default to `DEFERRED` but you can override the default type by passing `options.transactionType` in `new Sequelize`.
* Sqlite only. * Sqlite only.
* *
* The possible types to use when starting a transaction:
*
* ```js
* {
* DEFERRED: "DEFERRED",
* IMMEDIATE: "IMMEDIATE",
* EXCLUSIVE: "EXCLUSIVE"
* }
* ```
*
* Pass in the desired level as the first argument: * Pass in the desired level as the first argument:
* *
* ```js * ```js
* return sequelize.transaction({type: Sequelize.Transaction.EXCLUSIVE}, transaction => { * return sequelize.transaction({type: Sequelize.Transaction.TYPES.EXCLUSIVE}, transaction => {
* *
* // your transactions * // your transactions
* *
...@@ -193,8 +185,9 @@ class Transaction { ...@@ -193,8 +185,9 @@ class Transaction {
* // do something with the err. * // do something with the err.
* }); * });
* ``` * ```
* * @property DEFERRED
* @property TYPES * @property IMMEDIATE
* @property EXCLUSIVE
*/ */
Transaction.TYPES = { Transaction.TYPES = {
DEFERRED: 'DEFERRED', DEFERRED: 'DEFERRED',
...@@ -206,21 +199,10 @@ Transaction.TYPES = { ...@@ -206,21 +199,10 @@ Transaction.TYPES = {
* Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`. * Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`.
* Default to `REPEATABLE_READ` but you can override the default isolation level by passing `options.isolationLevel` in `new Sequelize`. * Default to `REPEATABLE_READ` but you can override the default isolation level by passing `options.isolationLevel` in `new Sequelize`.
* *
* The possible isolations levels to use when starting a transaction:
*
* ```js
* {
* READ_UNCOMMITTED: "READ UNCOMMITTED",
* READ_COMMITTED: "READ COMMITTED",
* REPEATABLE_READ: "REPEATABLE READ",
* SERIALIZABLE: "SERIALIZABLE"
* }
* ```
*
* Pass in the desired level as the first argument: * Pass in the desired level as the first argument:
* *
* ```js * ```js
* return sequelize.transaction({isolationLevel: Sequelize.Transaction.SERIALIZABLE}, transaction => { * return sequelize.transaction({isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.SERIALIZABLE}, transaction => {
* *
* // your transactions * // your transactions
* *
...@@ -230,8 +212,10 @@ Transaction.TYPES = { ...@@ -230,8 +212,10 @@ Transaction.TYPES = {
* // do something with the err. * // do something with the err.
* }); * });
* ``` * ```
* * @property READ_UNCOMMITTED
* @property ISOLATION_LEVELS * @property READ_COMMITTED
* @property REPEATABLE_READ
* @property SERIALIZABLE
*/ */
Transaction.ISOLATION_LEVELS = { Transaction.ISOLATION_LEVELS = {
READ_UNCOMMITTED: 'READ UNCOMMITTED', READ_UNCOMMITTED: 'READ UNCOMMITTED',
...@@ -245,15 +229,6 @@ Transaction.ISOLATION_LEVELS = { ...@@ -245,15 +229,6 @@ Transaction.ISOLATION_LEVELS = {
* *
* ```js * ```js
* t1 // is a transaction * t1 // is a transaction
* t1.LOCK.UPDATE,
* t1.LOCK.SHARE,
* t1.LOCK.KEY_SHARE, // Postgres 9.3+ only
* t1.LOCK.NO_KEY_UPDATE // Postgres 9.3+ only
* ```
*
* Usage:
* ```js
* t1 // is a transaction
* Model.findAll({ * Model.findAll({
* where: ..., * where: ...,
* transaction: t1, * transaction: t1,
...@@ -275,7 +250,10 @@ Transaction.ISOLATION_LEVELS = { ...@@ -275,7 +250,10 @@ Transaction.ISOLATION_LEVELS = {
* ``` * ```
* UserModel will be locked but TaskModel won't! * UserModel will be locked but TaskModel won't!
* *
* @property LOCK * @property UPDATE
* @property SHARE
* @property KEY_SHARE Postgres 9.3+ only
* @property NO_KEY_UPDATE Postgres 9.3+ only
*/ */
Transaction.LOCK = Transaction.prototype.LOCK = { Transaction.LOCK = Transaction.prototype.LOCK = {
UPDATE: 'UPDATE', UPDATE: 'UPDATE',
......
...@@ -358,6 +358,7 @@ exports.toDefaultValue = toDefaultValue; ...@@ -358,6 +358,7 @@ exports.toDefaultValue = toDefaultValue;
* *
* @param {*} value Any default value. * @param {*} value Any default value.
* @return {boolean} yes / no. * @return {boolean} yes / no.
* @private
*/ */
function defaultValueSchemable(value) { function defaultValueSchemable(value) {
if (typeof value === 'undefined') { return false; } if (typeof value === 'undefined') { return false; }
...@@ -449,6 +450,7 @@ exports.removeTicks = removeTicks; ...@@ -449,6 +450,7 @@ exports.removeTicks = removeTicks;
/** /**
* Utility functions for representing SQL functions, and columns that should be escaped. * Utility functions for representing SQL functions, and columns that should be escaped.
* Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead. * Please do not use these functions directly, use Sequelize.fn and Sequelize.col instead.
* @private
*/ */
class Fn { class Fn {
constructor(fn, args) { constructor(fn, args) {
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
const util = require('util'); const util = require('util');
const _ = require('lodash'); const _ = require('lodash');
/** like util.inherits, but also copies over static properties */ /**
* like util.inherits, but also copies over static properties
* @private
*/
function inherits(constructor, superConstructor) { function inherits(constructor, superConstructor) {
util.inherits(constructor, superConstructor); // Instance (prototype) methods util.inherits(constructor, superConstructor); // Instance (prototype) methods
_.extend(constructor, superConstructor); // Static methods _.extend(constructor, superConstructor); // Static methods
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* It require a `context` for which messages will be printed. * It require a `context` for which messages will be printed.
* *
* @module logging * @module logging
* @private
*/ */
/* jshint -W030 */ /* jshint -W030 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!