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

Commit d0e15380 by Jan Aagaard Meier

Update jsdocs for doclets

1 parent 37e6e63f
dir: lib
packageJson: package.json
articles:
- Getting started: docs/articles/getting-started.md
branches:
- master
- doclets
......@@ -34,7 +34,8 @@ 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()`.
*
* @mixin BelongsToMany
* @class BelongsToMany
* @memberof Associations
*/
class BelongsToMany extends Association {
constructor(source, target, options) {
......@@ -204,38 +205,46 @@ class BelongsToMany extends Association {
* @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
* @see {Model#findAll} for a full explanation of options
* @return {Promise<Array<Instance>>}
* @return {Promise<Array<Model>>}
* @method getAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
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.
*
* @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.validate] Run validation for the join model
* @return {Promise}
* @method setAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
set: 'set' + plural,
/**
* 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.validate] Run validation for the join model.
* @return {Promise}
* @method addAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
addMultiple: 'add' + plural,
/**
* 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.validate] Run validation for the join model.
* @return {Promise}
* @method addAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
add: 'add' + singular,
/**
......@@ -245,42 +254,52 @@ class BelongsToMany extends Association {
* @param {Object} [options] Options passed to create and add. Can also hold additional attributes for the join table
* @return {Promise}
* @method createAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
create: 'create' + singular,
/**
* 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`
* @return {Promise}
* @method removeAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
remove: 'remove' + singular,
/**
* 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`
* @return {Promise}
* @method removeAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
removeMultiple: 'remove' + plural,
/**
* 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
* @return {Promise}
* @method hasAssociation
* @memberof Associations.BelongsToMany
* @instance
*/
hasSingle: 'has' + singular,
/**
* 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
* @return {Promise}
* @method hasAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
hasAll: 'has' + plural,
/**
......@@ -289,8 +308,10 @@ class BelongsToMany extends Association {
* @param {Object} [options]
* @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
* @return {Promise<Int>}
* @return {Promise<Integer>}
* @method countAssociations
* @memberof Associations.BelongsToMany
* @instance
*/
count: 'count' + plural
};
......
......@@ -11,7 +11,8 @@ 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()`.
*
* @mixin BelongsTo
* @class BelongsTo
* @memberof Associations
*/
class BelongsTo extends Association {
constructor(source, target, options) {
......@@ -78,19 +79,21 @@ class BelongsTo extends Association {
* @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} [options.schema] Apply a schema on the related model
* @see {Model#findOne} for a full explanation of options
* @return {Promise<Instance>}
* @see {@link Model.findOne} for a full explanation of options
* @return {Promise<Model>}
* @method getAssociation
* @memberof Associations.BelongsTo
*/
get: 'get' + singular,
/**
* 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 {Boolean} [options.save=true] Skip saving this after setting the foreign key if false.
* @return {Promise}
* @method setAssociation
* @memberof Associations.BelongsTo
*/
set: 'set' + singular,
/**
......@@ -101,6 +104,7 @@ class BelongsTo extends Association {
* @see {Model#create} for a full explanation of options
* @return {Promise}
* @method createAssociation
* @memberof Associations.BelongsTo
*/
create: 'create' + singular
};
......
......@@ -10,7 +10,8 @@ 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()`.
*
* @mixin HasMany
* @class HasMany
* @memberof Associations
*/
class HasMany extends Association {
constructor(source, target, options) {
......@@ -98,38 +99,42 @@ class HasMany extends Association {
* @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
* @see {Model#findAll} for a full explanation of options
* @return {Promise<Array<Instance>>}
* @return {Promise<Array<Model>>}
* @method getAssociations
* @memberof Associations.HasMany
*/
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
*
* @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.validate] Run validation for the join model
* @return {Promise}
* @method setAssociations
* @memberof Associations.HasMany
*/
set: 'set' + plural,
/**
* 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.validate] Run validation for the join model.
* @return {Promise}
* @method addAssociations
* @memberof Associations.HasMany
*/
addMultiple: 'add' + plural,
/**
* 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.validate] Run validation for the join model.
* @return {Promise}
* @method addAssociation
* @memberof Associations.HasMany
*/
add: 'add' + singular,
/**
......@@ -139,42 +144,47 @@ class HasMany extends Association {
* @param {Object} [options] Options passed to `target.create`.
* @return {Promise}
* @method createAssociation
* @memberof Associations.HasMany
*/
create: 'create' + singular,
/**
* 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`
* @return {Promise}
* @method removeAssociation
* @memberof Associations.HasMany
*/
remove: 'remove' + singular,
/**
* 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`
* @return {Promise}
* @method removeAssociations
* @memberof Associations.HasMany
*/
removeMultiple: 'remove' + plural,
/**
* 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
* @return {Promise}
* @method hasAssociation
* @memberof Associations.HasMany
*/
hasSingle: 'has' + singular,
/**
* 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
* @return {Promise}
* @method hasAssociations
* @memberof Associations.HasMany
*/
hasAll: 'has' + plural,
/**
......@@ -183,8 +193,9 @@ class HasMany extends Association {
* @param {Object} [options]
* @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
* @return {Promise<Int>}
* @return {Promise<Integer>}
* @method countAssociations
* @memberof Associations.HasMany
*/
count: 'count' + plural
};
......@@ -333,7 +344,8 @@ class HasMany extends Association {
options = Utils.cloneDeep(options);
options.attributes = [
[sequelize.fn('COUNT', sequelize.col(model.primaryKeyField)), 'count']
[sequelize.fn('COUNT', sequelize.col([model.name, model.primaryKeyAttribute].join('.'))), 'count']
];
options.raw = true;
options.plain = true;
......
......@@ -11,7 +11,8 @@ 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()`.
* 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
*/
class HasOne extends Association {
constructor(srcModel, targetModel, options) {
......@@ -76,8 +77,9 @@ class HasOne extends Association {
* @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
* @see {Model#findOne} for a full explanation of options
* @return {Promise<Instance>}
* @return {Promise<Model>}
* @method getAssociation
* @memberof Associations.HasOne
*/
get: 'get' + singular,
/**
......@@ -87,6 +89,7 @@ class HasOne extends Association {
* @param {Object} [options] Options passed to getAssociation and `target.save`
* @return {Promise}
* @method setAssociation
* @memberof Associations.HasOne
*/
set: 'set' + singular,
/**
......@@ -97,6 +100,7 @@ class HasOne extends Association {
* @see {Model#create} for a full explanation of options
* @return {Promise}
* @method createAssociation
* @memberof Associations.HasOne
*/
create: 'create' + singular
};
......
......@@ -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.
*
* @mixin Associations
* @namespace Associations
* @name Associations
*/
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.onUpdate='CASCADE']
* @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
if (!target.prototype || !(target.prototype instanceof this.sequelize.Model)) {
......@@ -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.onUpdate='CASCADE']
* @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
if (!targetModel.prototype || !(targetModel.prototype instanceof this.sequelize.Model)) {
......@@ -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.onUpdate='CASCADE']
* @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);
......@@ -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.onUpdate='CASCADE']
* @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);
......
......@@ -53,7 +53,7 @@ const moment = require('moment');
* })
* ```
*
* @class DataTypes
* @namespace DataTypes
*/
function ABSTRACT() {}
......@@ -82,9 +82,8 @@ ABSTRACT.prototype.stringify = function stringify(value, options) {
/**
* A variable length string. Default length 255
*
* Available properties: `BINARY`
*
* @property STRING
* @property BINARY
* @memberof DataTypes
*/
function STRING(length, binary) {
const options = typeof length === 'object' && length || {length, binary};
......@@ -124,7 +123,7 @@ Object.defineProperty(STRING.prototype, 'BINARY', {
*
* Available properties: `BINARY`
*
* @property CHAR
* @memberof DataTypes
*/
function CHAR(length, binary) {
const options = typeof length === 'object' && length || {length, binary};
......@@ -141,7 +140,8 @@ CHAR.prototype.toSql = function toSql() {
/**
* An (un)limited length text column. Available lengths: `tiny`, `medium`, `long`
* @property TEXT
*
* @memberof DataTypes
*/
function TEXT(length) {
const options = typeof length === 'object' && length || {length};
......@@ -228,9 +228,9 @@ Object.defineProperty(NUMBER.prototype, 'ZEROFILL', {
/**
* A 32 bit integer.
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property INTEGER
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
function INTEGER(length) {
const options = typeof length === 'object' && length || {length};
......@@ -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).
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property BIGINT
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
function BIGINT(length) {
......@@ -277,9 +277,9 @@ BIGINT.prototype.validate = function validate(value) {
/**
* Floating point number (4-byte precision). Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property FLOAT
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
function FLOAT(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals};
......@@ -300,9 +300,9 @@ FLOAT.prototype.validate = function validate(value) {
/**
* Floating point number (4-byte precision). Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property REAL
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
function REAL(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals};
......@@ -316,9 +316,9 @@ REAL.prototype.key = REAL.key = 'REAL';
/**
* Floating point number (8-byte precision). Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property DOUBLE
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
function DOUBLE(length, decimals) {
const options = typeof length === 'object' && length || {length, decimals};
......@@ -332,9 +332,9 @@ DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION';
/**
* Decimal number. Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property DECIMAL
* @property UNSIGNED
* @property ZEROFILL
* @memberof DataTypes
*/
function DECIMAL(precision, scale) {
const options = typeof precision === 'object' && precision || {precision, scale};
......@@ -375,7 +375,8 @@ for (const floating of [FLOAT, DOUBLE, REAL]) {
/**
* A boolean / tinyint column, depending on dialect
* @property BOOLEAN
*
* @memberof DataTypes
*/
function BOOLEAN() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN();
......@@ -396,7 +397,8 @@ BOOLEAN.prototype.validate = function validate(value) {
/**
* A time column
* @property TIME
*
* @memberof DataTypes
*/
function TIME() {
......@@ -411,7 +413,8 @@ TIME.prototype.toSql = function toSql() {
/**
* A datetime column
* @property DATE
*
* @memberof DataTypes
*/
function DATE(length) {
const options = typeof length === 'object' && length || {length};
......@@ -458,7 +461,8 @@ DATE.prototype.$stringify = function $stringify(date, options) {
/**
* A date only column
* @property DATEONLY
*
* @memberof DataTypes
*/
function DATEONLY() {
......@@ -473,7 +477,8 @@ DATEONLY.prototype.toSql = function() {
/**
* A key / value column. Only available in postgres.
* @property HSTORE
*
* @memberof DataTypes
*/
function HSTORE() {
......@@ -492,7 +497,9 @@ HSTORE.prototype.validate = function validate(value) {
/**
* A JSON string column. Only available in postgres.
* @property JSON
*
* @function JSON
* @memberof DataTypes
*/
function JSONTYPE() {
if (!(this instanceof JSONTYPE)) return new JSONTYPE();
......@@ -510,7 +517,8 @@ JSONTYPE.prototype.$stringify = function $stringify(value, options) {
/**
* A pre-processed JSON data column. Only available in postgres.
* @property JSONB
*
* @memberof DataTypes
*/
function JSONB() {
if (!(this instanceof JSONB)) return new JSONB();
......@@ -522,7 +530,8 @@ JSONB.prototype.key = JSONB.key = 'JSONB';
/**
* A default value of the current timestamp
* @property NOW
*
* @memberof DataTypes
*/
function NOW() {
if (!(this instanceof NOW)) return new NOW();
......@@ -534,7 +543,7 @@ NOW.prototype.key = NOW.key = 'NOW';
/**
* Binary storage. Available lengths: `tiny`, `medium`, `long`
*
* @property BLOB
* @memberof DataTypes
*/
function BLOB(length) {
const options = typeof length === 'object' && length || {length};
......@@ -587,7 +596,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).
* Only available in postgres.
* See {@link http://www.postgresql.org/docs/9.4/static/rangetypes.html|Postgres documentation} for more details
* @property RANGE
*
* @memberof DataTypes
*/
function RANGE(subtype) {
......@@ -650,7 +660,8 @@ RANGE.prototype.validate = function validate(value) {
/**
* A column storing a unique universal identifier. Use with `UUIDV1` or `UUIDV4` for default values.
* @property UUID
*
* @memberof DataTypes
*/
function UUID() {
if (!(this instanceof UUID)) return new UUID();
......@@ -668,7 +679,8 @@ UUID.prototype.validate = function validate(value, options) {
/**
* A default unique universal identifier generated following the UUID v1 standard
* @property UUIDV1
*
* @memberof DataTypes
*/
function UUIDV1() {
......@@ -687,7 +699,8 @@ UUIDV1.prototype.validate = function validate(value, options) {
/**
* A default unique universal identifier generated following the UUID v4 standard
* @property UUIDV4
*
* @memberof DataTypes
*/
function UUIDV4() {
......@@ -743,8 +756,7 @@ UUIDV4.prototype.validate = function validate(value, options) {
* }
* ```
*
* @property VIRTUAL
* @alias NONE
* @memberof DataTypes
*/
function VIRTUAL(ReturnType, fields) {
if (!(this instanceof VIRTUAL)) return new VIRTUAL(ReturnType, fields);
......@@ -760,7 +772,7 @@ VIRTUAL.prototype.key = VIRTUAL.key = 'VIRTUAL';
/**
* An enumeration. `DataTypes.ENUM('value', 'another value')`.
*
* @property ENUM
* @memberof DataTypes
*/
function ENUM(value) {
const options = typeof value === 'object' && !Array.isArray(value) && value || {
......@@ -785,7 +797,8 @@ ENUM.prototype.validate = function validate(value) {
/**
* An array of `type`, e.g. `DataTypes.ARRAY(DataTypes.DECIMAL)`. Only available in postgres.
* @property ARRAY
*
* @memberof DataTypes
*/
function ARRAY(type) {
const options = _.isPlainObject(type) ? type : {type};
......@@ -865,7 +878,7 @@ const helpers = {
* });
* ```
*
* @property GEOMETRY
* @memberof DataTypes
*/
function GEOMETRY(type, srid) {
......@@ -888,7 +901,8 @@ GEOMETRY.prototype.$stringify = function $stringify(value) {
/**
* A geography datatype represents two dimensional spacial objects in an elliptic coord system.
* @property GEOGRAPHY
*
* @memberof DataTypes
*/
function GEOGRAPHY(type, srid) {
......
......@@ -34,7 +34,12 @@ 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.
*/
var Deferrable = module.exports = {
INITIALLY_DEFERRED: INITIALLY_DEFERRED,
......@@ -50,12 +55,6 @@ ABSTRACT.prototype.toString = function () {
return this.toSql.apply(this, arguments);
};
/**
* A property that will defer constraints checks to the end of transactions.
*
* @property INITIALLY_DEFERRED
*/
function INITIALLY_DEFERRED () {
if (!(this instanceof INITIALLY_DEFERRED)) {
return new INITIALLY_DEFERRED();
......@@ -67,12 +66,6 @@ INITIALLY_DEFERRED.prototype.toSql = function () {
return 'DEFERRABLE INITIALLY DEFERRED';
};
/**
* A property that will trigger the constraint checks immediately
*
* @property INITIALLY_IMMEDIATE
*/
function INITIALLY_IMMEDIATE () {
if (!(this instanceof INITIALLY_IMMEDIATE)) {
return new INITIALLY_IMMEDIATE();
......@@ -84,14 +77,6 @@ INITIALLY_IMMEDIATE.prototype.toSql = function () {
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 () {
if (!(this instanceof NOT)) {
return new NOT();
......@@ -109,7 +94,7 @@ NOT.prototype.toSql = function () {
* transaction which sets the constraints to deferred.
*
* @param {Array} constraints An array of constraint names. Will defer all constraints by default.
* @property SET_DEFERRED
* @memberof Sequelize.Deferrable
*/
function SET_DEFERRED (constraints) {
if (!(this instanceof SET_DEFERRED)) {
......@@ -130,7 +115,7 @@ SET_DEFERRED.prototype.toSql = function (queryGenerator) {
* transaction which sets the constraints to immediately.
*
* @param {Array} constraints An array of constraint names. Will defer all constraints by default.
* @property SET_IMMEDIATE
* @memberof Sequelize.Deferrable
*/
function SET_IMMEDIATE (constraints) {
if (!(this instanceof SET_IMMEDIATE)) {
......
......@@ -11,11 +11,6 @@ const BelongsTo = require('../../associations/belongs-to');
const uuid = require('node-uuid');
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 = {
options: {},
......@@ -46,33 +41,10 @@ const QueryGenerator = {
};
},
/*
Returns a query for dropping a schema
*/
dropSchema(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) {
const table = this.quoteTable(
this.addSchema({
......@@ -85,90 +57,19 @@ const QueryGenerator = {
return 'DESCRIBE ' + table + ';';
},
/*
Returns a query for dropping a table.
*/
dropTableQuery(tableName, options) {
options = options || {};
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) {
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.
@private
*/
insertQuery(table, valueHash, modelAttributes, options) {
options = options || {};
......@@ -310,6 +211,7 @@ const QueryGenerator = {
/*
Returns an insert into command for multiple values.
Parameters: table name + list of hashes of attribute-value-pairs.
@private
*/
bulkInsertQuery(tableName, attrValueHashes, options, rawAttributes) {
options = options || {};
......@@ -371,6 +273,7 @@ const QueryGenerator = {
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.
@private
*/
updateQuery(tableName, attrValueHash, where, options, attributes) {
options = options || {};
......@@ -467,34 +370,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.
Parameters:
- tableName -> Name of the table
......@@ -503,6 +378,7 @@ const QueryGenerator = {
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.
@private
*/
incrementQuery(tableName, attrValueHash, where, options) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull);
......@@ -565,6 +441,7 @@ const QueryGenerator = {
- order: 'ASC' or 'DESC'. Optional
- parser
- rawTablename, the name of the table, without schema. Used to create the name of the index
@private
*/
addIndexQuery(tableName, attributes, options, rawTablename) {
options = options || {};
......@@ -678,47 +555,6 @@ const QueryGenerator = {
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) {
let table = '';
......@@ -773,6 +609,7 @@ const QueryGenerator = {
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)
@private
*/
quote(obj, parent, force) {
if (Utils._.isString(obj)) {
......@@ -843,65 +680,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
@private
*/
quoteIdentifiers(identifiers, force) {
quoteIdentifiers(identifiers) {
if (identifiers.indexOf('.') !== -1) {
identifiers = identifiers.split('.');
return this.quoteIdentifier(identifiers.slice(0, identifiers.length - 1).join('.')) + '.' + this.quoteIdentifier(identifiers[identifiers.length - 1]);
......@@ -912,6 +694,7 @@ const QueryGenerator = {
/*
Escape a value (e.g. a string, number or date)
@private
*/
escape(value, field, options) {
options = options || {};
......@@ -949,31 +732,6 @@ const QueryGenerator = {
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>.
Options:
......@@ -986,6 +744,7 @@ const QueryGenerator = {
- group
- limit -> The maximum count you want to get.
- offset -> An offset value to start from. Only useable with limit!
@private
*/
selectQuery(tableName, options, model) {
......@@ -1645,6 +1404,7 @@ const QueryGenerator = {
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @param {Object} options An object with options.
* @return {String} The generated sql query.
* @private
*/
setAutocommitQuery(value, options) {
if (options.parent) {
......@@ -1665,6 +1425,7 @@ const QueryGenerator = {
* @param {String} value The isolation level.
* @param {Object} options An object with options.
* @return {String} The generated sql query.
* @private
*/
setIsolationLevelQuery(value, options) {
if (options.parent) {
......@@ -1680,6 +1441,7 @@ const QueryGenerator = {
* @param {Transaction} transaction
* @param {Object} options An object with options.
* @return {String} The generated sql query.
* @private
*/
startTransactionQuery(transaction) {
if (transaction.parent) {
......@@ -1696,6 +1458,7 @@ const QueryGenerator = {
* @param {Transaction} transaction
* @param {Object} options An object with options.
* @return {String} The generated sql query.
* @private
*/
deferConstraintsQuery() {},
......@@ -1708,6 +1471,7 @@ const QueryGenerator = {
*
* @param {Object} options An object with options.
* @return {String} The generated sql query.
* @private
*/
commitTransactionQuery(transaction) {
if (transaction.parent) {
......@@ -1723,6 +1487,7 @@ const QueryGenerator = {
* @param {Transaction} transaction
* @param {Object} options An object with options.
* @return {String} The generated sql query.
* @private
*/
rollbackTransactionQuery(transaction) {
if (transaction.parent) {
......@@ -1739,8 +1504,9 @@ const QueryGenerator = {
* @param {Object} options An object with selectQuery options.
* @param {Object} options The model passed to the selectQuery.
* @return {String} The generated sql query.
* @private
*/
addLimitAndOffset(options, model) {
addLimitAndOffset(options) {
let fragment = '';
/*jshint eqeqeq:false*/
......@@ -2242,6 +2008,7 @@ const QueryGenerator = {
/*
Takes something and transforms it into values of a where condition.
@private
*/
getWhereConditions(smth, tableName, factory, options, prepend) {
let result = null;
......
......@@ -19,6 +19,7 @@ class AbstractQuery {
* Options
* skipUnescape: bool, skip unescaping $$
* 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) {
if (!values) {
......@@ -94,7 +95,7 @@ class AbstractQuery {
* query.run('SELECT 1')
*
* @param {String} sql - The SQL query which should be executed.
* @api public
* @private
*/
run() {
throw new Error('The run method wasn\'t overwritten!');
......@@ -104,6 +105,7 @@ class AbstractQuery {
* Check the logging option of the instance and print deprecation warnings.
*
* @return {void}
* @private
*/
checkLoggingOption() {
if (this.options.logging === true) {
......@@ -116,6 +118,7 @@ class AbstractQuery {
* Get the attributes of an insert query, which contains the just inserted id.
*
* @return {String} The field name.
* @private
*/
getInsertIdField() {
return 'insertId';
......@@ -127,6 +130,7 @@ class AbstractQuery {
*
* @param {String} attribute An attribute of a SQL query. (?)
* @return {String} The found tableName / alias.
* @private
*/
findTableNameInAttribute(attribute) {
if (!this.options.include) {
......@@ -353,6 +357,7 @@ class AbstractQuery {
* ]
* }
* ]
* @private
*/
static $groupJoinData(rows, includeOptions, options) {
......
......@@ -5,6 +5,7 @@
@class QueryInterface
@static
@private
*/
/**
......@@ -17,6 +18,7 @@
@param {String} attributeName The name of the attribute that we want to remove.
@param {Object} options
@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 self = this;
......
......@@ -128,6 +128,7 @@ class Query extends AbstractQuery {
* ])
*
* @param {Array} data - The result of the query execution.
* @private
*/
formatResults(data) {
let result = this.instance;
......
......@@ -299,6 +299,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema.
* @return {String} The generated sql query.
* @private
*/
getForeignKeysQuery(tableName, schemaName) {
return "SELECT CONSTRAINT_NAME as constraint_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where TABLE_NAME = '" + tableName + /* jshint ignore: line */
......@@ -311,6 +312,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table.
* @param {String} columnName The name of the column.
* @return {String} The generated sql query.
* @private
*/
getForeignKeyQuery(table, columnName) {
let tableName = table.tableName || table;
......@@ -332,6 +334,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table.
* @param {String} foreignKey The name of the foreign key constraint.
* @return {String} The generated sql query.
* @private
*/
dropForeignKeyQuery(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP FOREIGN KEY ' + this.quoteIdentifier(foreignKey) + ';';
......
......@@ -5,6 +5,7 @@
@class QueryInterface
@static
@private
*/
const _ = require('lodash');
......@@ -18,6 +19,7 @@ const _ = require('lodash');
@param {String} tableName The name of the table.
@param {String} columnName The name of the attribute that we want to remove.
@param {Object} options
@private
*/
function removeColumn(tableName, columnName, options) {
options = options || {};
......
......@@ -85,6 +85,7 @@ class Query extends AbstractQuery {
* ])
*
* @param {Array} data - The result of the query execution.
* @private
*/
formatResults(data) {
let result = this.instance;
......
......@@ -763,6 +763,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema.
* @return {String} The generated sql query.
* @private
*/
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 ' +
......@@ -775,6 +776,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table.
* @param {String} foreignKey The name of the foreign key constraint.
* @return {String} The generated sql query.
* @private
*/
dropForeignKeyQuery(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP CONSTRAINT ' + this.quoteIdentifier(foreignKey) + ';';
......
......@@ -26,6 +26,7 @@ class Query extends AbstractQuery {
/**
* rewrite query with parameters
* @private
*/
static formatBindParameters(sql, values, dialect) {
let bindParam = [];
......
......@@ -343,6 +343,7 @@ const QueryGenerator = {
* @param {String} tableName The name of the table.
* @param {String} schemaName The name of the schema.
* @return {String} The generated sql query.
* @private
*/
getForeignKeysQuery(tableName, schemaName) {
return `PRAGMA foreign_key_list(${tableName})`;
......
......@@ -8,6 +8,7 @@ const Promise = require('../../promise');
@class QueryInterface
@static
@private
*/
/**
......@@ -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
@since 1.6.0
@private
*/
function removeColumn(tableName, attributeName, options) {
options = options || {};
......@@ -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
@since 1.6.0
@private
*/
function changeColumn(tableName, attributes, options) {
const attributeName = Object.keys(attributes)[0];
......@@ -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
@since 1.6.0
@private
*/
function renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
options = options || {};
......
......@@ -32,6 +32,7 @@ class Query extends AbstractQuery {
/**
* rewrite query with parameters
* @private
*/
static formatBindParameters(sql, values, dialect) {
let bindParam;
......
......@@ -5,14 +5,14 @@
* All sequelize errors inherit from the base JS error object.
*
* @fileOverview The Error Objects produced by Sequelize.
* @class Errors
* @namespace Errors
*/
/**
* The Base Error all Sequelize Errors inherit from.
*
* @constructor
* @alias Error
* @memberof Errors
*/
class BaseError extends Error {
constructor(message) {
......@@ -30,7 +30,7 @@ exports.BaseError = BaseError;
* @param {string} message Error message
*
* @extends BaseError
* @constructor
* @memberof Errors
*/
class SequelizeScopeError extends BaseError {
constructor(parent) {
......@@ -48,17 +48,15 @@ exports.SequelizeScopeError = SequelizeScopeError;
* @param {Array} [errors] Array of ValidationErrorItem objects describing the validation errors
*
* @extends BaseError
* @constructor
* @memberof Errors
*
* @property errors An array of ValidationErrorItems
*/
class ValidationError extends BaseError {
constructor(message, errors) {
super(message);
this.name = 'SequelizeValidationError';
this.message = 'Validation Error';
/**
* An array of ValidationErrorItems
* @member errors
*/
this.errors = errors || [];
// Use provided error message if available...
......@@ -91,43 +89,23 @@ exports.ValidationError = ValidationError;
/**
* A base class for all database related errors.
* @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 {
constructor(parent) {
super(parent.message);
this.name = 'SequelizeDatabaseError';
/**
* The database specific error which triggered this one
* @member parent
*/
this.parent = parent;
this.original = parent;
/**
* The SQL that triggered the error
* @member 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;
......@@ -135,7 +113,7 @@ exports.DatabaseError = DatabaseError;
/**
* Thrown when a database query times out because of a deadlock
* @extends DatabaseError
* @constructor
* @memberof Errors
*/
class TimeoutError extends BaseError {
constructor(parent) {
......@@ -148,7 +126,7 @@ exports.TimeoutError = TimeoutError;
/**
* Thrown when a unique constraint is violated in the database
* @extends DatabaseError
* @constructor
* @memberof Errors
*/
class UniqueConstraintError extends ValidationError {
constructor(options) {
......@@ -169,7 +147,7 @@ exports.UniqueConstraintError = UniqueConstraintError;
/**
* Thrown when a foreign key constraint is violated in the database
* @extends DatabaseError
* @constructor
* @memberof Errors
*/
class ForeignKeyConstraintError extends DatabaseError {
constructor(options) {
......@@ -191,7 +169,7 @@ exports.ForeignKeyConstraintError = ForeignKeyConstraintError;
/**
* Thrown when an exclusion constraint is violated in the database
* @extends DatabaseError
* @constructor
* @memberof Errors
*/
class ExclusionConstraintError extends DatabaseError {
constructor(options) {
......@@ -217,7 +195,7 @@ exports.ExclusionConstraintError = ExclusionConstraintError;
* @param {string} type The type of the validation error
* @param {string} path The field that triggered the validation error
* @param {string} value The value that generated the error
* @constructor
* @memberof Errors
*/
class ValidationErrorItem {
constructor(message, type, path, value) {
......@@ -232,7 +210,7 @@ exports.ValidationErrorItem = ValidationErrorItem;
/**
* A base class for all connection related errors.
* @extends BaseError
* @constructor
* @memberof Errors
*/
class ConnectionError extends BaseError {
constructor(parent) {
......@@ -251,7 +229,7 @@ exports.ConnectionError = ConnectionError;
/**
* Thrown when a connection to a database is refused
* @extends ConnectionError
* @constructor
* @memberof Errors
*/
class ConnectionRefusedError extends ConnectionError {
constructor(parent) {
......@@ -264,7 +242,8 @@ exports.ConnectionRefusedError = ConnectionRefusedError;
/**
* Thrown when a connection to a database is refused due to insufficient privileges
* @extends ConnectionError
* @constructor
* @memberof Errors
* @memberof Sequelize
*/
class AccessDeniedError extends ConnectionError {
constructor(parent) {
......@@ -277,7 +256,7 @@ exports.AccessDeniedError = AccessDeniedError;
/**
* Thrown when a connection to a database has a hostname that was not found
* @extends ConnectionError
* @constructor
* @memberof Errors
*/
class HostNotFoundError extends ConnectionError {
constructor(parent) {
......@@ -290,7 +269,7 @@ exports.HostNotFoundError = HostNotFoundError;
/**
* Thrown when a connection to a database has a hostname that was not reachable
* @extends ConnectionError
* @constructor
* @memberof Errors
*/
class HostNotReachableError extends ConnectionError {
constructor(parent) {
......@@ -303,7 +282,7 @@ exports.HostNotReachableError = HostNotReachableError;
/**
* Thrown when a connection to a database has invalid values for any of the connection parameters
* @extends ConnectionError
* @constructor
* @memberof Errors
*/
class InvalidConnectionError extends ConnectionError {
constructor(parent) {
......@@ -316,7 +295,7 @@ exports.InvalidConnectionError = InvalidConnectionError;
/**
* Thrown when a connection to a database times out
* @extends ConnectionError
* @constructor
* @memberof Errors
*/
class ConnectionTimedOutError extends ConnectionError {
constructor(parent) {
......@@ -329,7 +308,7 @@ exports.ConnectionTimedOutError = ConnectionTimedOutError;
/**
* Thrown when a some problem occurred with Instance methods (see message for details)
* @extends BaseError
* @constructor
* @memberof Errors
*/
class InstanceError extends BaseError {
constructor(message) {
......@@ -343,7 +322,7 @@ exports.InstanceError = InstanceError;
/**
* Thrown when a record was not found, Usually used with rejectOnEmpty mode (see message for details)
* @extends BaseError
* @constructor
* @memberof Errors
*/
class EmptyResultError extends BaseError {
constructor(message) {
......
......@@ -10,6 +10,7 @@ const Utils = require('./utils')
* 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 }, {
......@@ -86,6 +87,7 @@ const hookAliases = {
/**
* get array of current hook and its proxied hooks combined
* @private
*/
const getProxiedHooks = (hookType) => (
hookTypes[hookType].proxies
......@@ -221,7 +223,7 @@ const Hooks = {
return this;
},
/*
/**
* Check whether the mode has any hooks of this type
*
* @param {String} hookType
......
......@@ -14,6 +14,7 @@ const _ = require('lodash');
* @param {Instance} modelInstance The model instance.
* @param {Object} options A dict with options.
* @constructor
* @private
*/
class InstanceValidator {
......@@ -34,6 +35,7 @@ class InstanceValidator {
/**
* Exposes a reference to validator.js. This allows you to add custom validations using `validator.extend`
* @name validator
* @private
*/
this.validator = validator;
......@@ -42,10 +44,14 @@ class InstanceValidator {
*
* @type {Array} Will contain keys that correspond to attributes which will
* be Arrays of Errors.
* @private
*/
this.errors = [];
/** @type {boolean} Indicates if validations are in progress */
/**
* @type {boolean} Indicates if validations are in progress
* @private
*/
this.inProgress = false;
extendModelValidations(modelInstance);
......@@ -55,6 +61,7 @@ class InstanceValidator {
* The main entry point for the Validation module, invoke to start the dance.
*
* @return {Promise}
* @private
*/
_validate() {
if (this.inProgress) {
......@@ -79,6 +86,7 @@ class InstanceValidator {
* - On validation failure: Validation Failed Model Hooks
*
* @return {Promise}
* @private
*/
validate() {
if (this.options.hooks) {
......@@ -344,7 +352,10 @@ class InstanceValidator {
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';
module.exports = InstanceValidator;
......
......@@ -40,6 +40,7 @@ class ModelManager {
* Iterate over Models in an order suitable for e.g. creating tables. Will
* take foreign key constraints into account so that dependencies are visited
* before dependents.
* @private
*/
forEachModel(iterator, options) {
const models = {};
......
......@@ -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`.
* 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
* @mixes Hooks
* @mixes Associations
*/
class Model {
......@@ -899,7 +898,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)
* @see {Sequelize#sync} for options
* @see {@link Sequelize#sync} for options
* @return {Promise<this>}
*/
static sync(options) {
......@@ -973,7 +972,7 @@ class Model {
* @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).
*
* @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}
*/
......@@ -1088,7 +1087,7 @@ class Model {
* // 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.
*/
static scope(option) {
......@@ -1220,7 +1219,9 @@ class Model {
* 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.where] A hash of attributes to describe your search. See above for examples.
......@@ -1254,11 +1255,9 @@ class Model {
* @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
*
* @see {Sequelize#query}
* @return {Promise<Array<Instance>>}
* @alias all
* @see {@link Sequelize#query}
* @return {Promise<Array<Model>>}
*/
static findAll(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');
......@@ -1398,14 +1397,15 @@ class Model {
/**
* 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 {Object} [options]
* @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)
*
* @see {Model#findAll} for a full explanation of options
* @return {Promise<Instance>}
* @alias findByPrimary
* @see {@link Model#findAll} for a full explanation of options
* @return {Promise<Model>}
*/
static findById(param, options) {
// return Promise resolved with null if no arguments are passed
......@@ -1429,13 +1429,14 @@ class Model {
/**
* 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 {Transaction} [options.transaction] Transaction to run query under
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
*
* @see {Model#findAll} for an explanation of options
* @return {Promise<Instance>}
* @alias find
* @see {@link Model#findAll} for an explanation of options
* @return {Promise<Model>}
*/
static findOne(options) {
if (options !== undefined && !_.isPlainObject(options)) {
......@@ -1594,11 +1595,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
*
* __Alias__: _findAndCountAll_
*
* @param {Object} [findOptions] See findAll
*
* @see {Model#findAll} for a specification of find and query options
* @return {Promise<Object>}
* @alias findAndCountAll
* @see {@link Model#findAll} for a specification of find and query options
* @return {Promise<{count: Integer, rows: Model[]}>}
*/
static findAndCount(options) {
if (options !== undefined && !_.isPlainObject(options)) {
......@@ -1655,7 +1657,7 @@ class Model {
*
* @param {String} field
* @param {Object} [options] See aggregate
* @see {Model#aggregate} for options
* @see {@link Model#aggregate} for options
*
* @return {Promise<Any>}
*/
......@@ -1668,7 +1670,7 @@ class Model {
*
* @param {String} field
* @param {Object} [options] See aggregate
* @see {Model#aggregate} for options
* @see {@link Model#aggregate} for options
*
* @return {Promise<Any>}
*/
......@@ -1681,7 +1683,7 @@ class Model {
*
* @param {String} field
* @param {Object} [options] See aggregate
* @see {Model#aggregate} for options
* @see {@link Model#aggregate} for options
*
* @return {Promise<Number>}
*/
......@@ -1731,8 +1733,8 @@ class Model {
/**
* Builds a new model instance and calls save on it.
* @see {Instance#build}
* @see {Instance#save}
* @see {@link Model#build}
* @see {@link Model#save}
*
* @param {Object} values
* @param {Object} [options]
......@@ -1750,7 +1752,7 @@ class Model {
* @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)
*
* @return {Promise<Instance>}
* @return {Promise<Model>}
*
*/
static create(values, options) {
......@@ -1769,6 +1771,8 @@ class Model {
* 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()
*
* __Alias__: _findOrInitialize_
*
* @param {Object} options
* @param {Object} options.where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if building a new instance
......@@ -1776,8 +1780,7 @@ class Model {
* @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).
*
* @return {Promise<Instance,initialized>}
* @alias findOrBuild
* @return {Promise<Model,initialized>}
*/
static findOrBuild(options) {
if (!options || !options.where || arguments.length > 1) {
......@@ -1817,8 +1820,8 @@ class Model {
* @param {Object} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance
* @param {Transaction} [options.transaction] Transaction to run query under
* @see {Model#findAll} for a full specification of find and options
* @return {Promise<Instance,created>}
* @see {@link Model#findAll} for a full specification of find and options
* @return {Promise<Model,created>}
*/
static findOrCreate(options) {
if (!options || !options.where || arguments.length > 1) {
......@@ -1910,8 +1913,8 @@ class Model {
* @param {Object} options
* @param {Object} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance
* @see {Model#findAll} for a full specification of find and options
* @return {Promise<Instance,created>}
* @see {@link Model#findAll} for a full specification of find and options
* @return {Promise<Model,created>}
*/
static findCreateFind(options) {
if (!options || !options.where) {
......@@ -1946,6 +1949,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.
*
* __Alias__: _insertOrUpdate_
*
* @param {Object} values
* @param {Object} [options]
* @param {Boolean} [options.validate=true] Run validations before the row is inserted
......@@ -1956,7 +1961,6 @@ class Model {
* @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)
*
* @alias insertOrUpdate
* @return {Promise<created>} Returns a boolean indicating whether the row was created or updated.
*/
static upsert(values, options) {
......@@ -2172,7 +2176,7 @@ class Model {
*
* @return {Promise}
*
* @see {Model#destroy} for more information
* @see {@link Model#destroy} for more information
*/
static truncate(options) {
options = Utils.cloneDeep(options) || {};
......@@ -2657,7 +2661,7 @@ class Model {
/**
* Returns the Model the instance was created from.
* @see {Model}
* @see {@link Model}
* @property Model
* @return {Model}
*/
......@@ -2718,7 +2722,7 @@ class Model {
/**
* A reference to the sequelize instance
* @see {Sequelize}
* @see {@link Sequelize}
* @property sequelize
* @return {Sequelize}
*/
......@@ -2846,13 +2850,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.
*
* @see {Model#find} for more information about includes
* @see {@link Model#find} for more information about includes
* @param {String|Object} key
* @param {any} value
* @param {Object} [options]
* @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
* @alias setAttributes
*/
set(key, value, options) { // testhint options:none
let values;
......@@ -3314,14 +3317,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.
* 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.
*
* @see {Model#find}
* @see {@link 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.
*
* @return {Promise<this>}
*/
reload(options) {
......@@ -3350,15 +3354,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.
*
* @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 {Boolean} [options.hooks=true] Run before and after validate hooks
* @see {InstanceValidator}
*
* @return {Promise<undefined|Errors.ValidationError>}
*/
......@@ -3370,13 +3373,12 @@ class Model {
* 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.
*
* @see {Instance#set}
* @see {Instance#save}
* @see {@link Model#set}
* @see {@link Model#save}
* @param {Object} updates See `set`
* @param {Object} options See `save`
*
* @return {Promise<this>}
* @alias updateAttributes
*/
update(values, options) {
const changedBefore = this.changed() || [];
......@@ -3500,7 +3502,7 @@ class Model {
* // `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 {Object} [options]
* @param {Integer} [options.by=1] The number to increment by
......@@ -3562,7 +3564,7 @@ class Model {
* // `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 {Object} [options]
* @param {Integer} [options.by=1] The number to decrement by
......@@ -3591,7 +3593,7 @@ class Model {
/**
* Check whether this and `other` Instance refer to the same row
*
* @param {Instance} other
* @param {Model} other
* @return {Boolean}
*/
equals(other) {
......@@ -3624,7 +3626,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.
*
* @see {Instance#get}
* @see {@link Model#get}
* @return {object}
*/
toJSON() {
......
......@@ -13,6 +13,7 @@ const QueryTypes = require('./query-types');
/**
* The interface that Sequelize uses to talk to all databases
* @class QueryInterface
* @private
*/
class QueryInterface {
constructor(sequelize) {
......@@ -765,6 +766,7 @@ class QueryInterface {
* 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
* false.
* @private
*/
quoteIdentifier(identifier, force) {
return this.QueryGenerator.quoteIdentifier(identifier, force);
......@@ -778,6 +780,7 @@ class QueryInterface {
* Split an identifier into .-separated tokens and quote each part.
* If force is true, the identifier will be quoted even if the
* `quoteIdentifiers` option is false.
* @private
*/
quoteIdentifiers(identifiers, force) {
return this.QueryGenerator.quoteIdentifiers(identifiers, force);
......@@ -785,6 +788,7 @@ class QueryInterface {
/**
* Escape a value (e.g. a string, number or date)
* @private
*/
escape(value) {
return this.QueryGenerator.escape(value);
......
......@@ -28,6 +28,7 @@ const _ = require('lodash');
* In addition to sequelize, the connection library for the dialect you want to use should also be installed in your project. You don't need to import it however, as sequelize will take care of that.
*
* @class Sequelize
* @lands Errors
*/
/**
......@@ -239,7 +240,6 @@ class Sequelize {
/**
* Models are stored here under the name given to `sequelize.define`
* @property models
*/
this.models = {};
this.modelManager = new ModelManager(this);
......@@ -283,8 +283,6 @@ class Sequelize {
* @method getQueryInterface
* @return {QueryInterface} An instance (singleton) of QueryInterface.
*
* @see {QueryInterface}
*/
getQueryInterface() {
this.queryInterface = this.queryInterface || new QueryInterface(this);
......@@ -329,8 +327,8 @@ class Sequelize {
*
* For more about validation, see http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations
*
* @see {DataTypes}
* @see {Hooks}
* @see {@link DataTypes}
* @see {@link Hooks}
* @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. 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
......@@ -359,7 +357,7 @@ class Sequelize {
* @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.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 {String} [options.name.singular=Utils.singularize(modelName)]
* @param {String} [options.name.plural=Utils.pluralize(modelName)]
......@@ -423,6 +421,7 @@ class Sequelize {
this.runHooks('afterDefine', model);
return model;
}
......@@ -523,8 +522,9 @@ class Sequelize {
* @param {Object} [options.fieldMap] Map returned fields to arbitrary names for `SELECT` query type.
*
* @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) {
if (arguments.length > 2) {
......@@ -653,6 +653,7 @@ class Sequelize {
* @param {Object} options Query options.
* @param {Transaction} options.transaction The transaction that the query should be executed under
*
* @memberof Sequelize
* @return {Promise}
*/
set(variables, options) {
......@@ -693,10 +694,10 @@ class Sequelize {
/**
* 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.
*
* @see {Model#schema}
* @see {@link Model#schema}
* @param {String} schema Name of the schema
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
......@@ -709,7 +710,7 @@ class Sequelize {
/**
* 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.
* @param {Object} options={}
* @param {Boolean|function} options.logging A function that logs sql queries, or false for no logging
......@@ -722,7 +723,7 @@ class Sequelize {
/**
* 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
* @param {String} schema Name of the schema
* @param {Object} options={}
......@@ -750,8 +751,8 @@ class Sequelize {
* Sync all defined models to the DB.
*
* @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 {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 {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 {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 {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)
......@@ -809,7 +810,7 @@ class Sequelize {
* @param {Boolean|function} [options.logging] A function that logs sql queries, or false for no logging
* @return {Promise}
*
* @see {Model#truncate} for more information
* @see {@link Model#truncate} for more information
*/
truncate(options) {
const models = [];
......@@ -831,7 +832,7 @@ class Sequelize {
/**
* 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 {Boolean|function} options.logging A function that logs sql queries, or false for no logging
......@@ -852,9 +853,7 @@ class Sequelize {
/**
* 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...)
* @alias validate
* @return {Promise}
*/
authenticate(options) {
......@@ -876,16 +875,17 @@ class Sequelize {
* })
* ```
*
* @see {Model#find}
* @see {Model#findAll}
* @see {Model#define}
* @see {Sequelize#col}
* @see {@link Model#find}
* @see {@link Model#findAll}
* @see {@link Model#define}
* @see {@link Sequelize#col}
* @method fn
*
* @param {String} fn The function you want to call
* @param {any} args All further arguments will be passed as arguments to the function
*
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.fn}
*/
static fn(fn) {
......@@ -894,11 +894,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.
* @see {Sequelize#fn}
* @see {@link Sequelize#fn}
*
* @method col
* @param {String} col The name of the column
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.col}
*/
static col(col) {
......@@ -912,6 +913,7 @@ class Sequelize {
* @param {any} val The value to cast
* @param {String} type The type to cast it to
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.cast}
*/
static cast(val, type) {
......@@ -925,6 +927,7 @@ class Sequelize {
* @param {any} val
* @alias asIs
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.literal}
*/
static literal(val) {
......@@ -933,11 +936,12 @@ class Sequelize {
/**
* An AND query
* @see {Model#find}
* @see {@link Model#find}
*
* @method and
* @param {String|Object} args Each argument will be joined by AND
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.and}
*/
static and() {
......@@ -946,11 +950,12 @@ class Sequelize {
/**
* An OR query
* @see {Model#find}
* @see {@link Model#find}
*
* @method or
* @param {String|Object} args Each argument will be joined by OR
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.or}
*/
static or() {
......@@ -959,11 +964,12 @@ class Sequelize {
/**
* Creates an object representing nested where conditions for postgres's json data-type.
* @see {Model#find}
* @see {@link Model#find}
*
* @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|Number|Boolean} [value] An optional value to compare against. Produces a string of the form "<json path> = '<value>'".
* @memberof Sequelize
* @return {Sequelize.json}
*/
static json(conditionsOrPath, value) {
......@@ -978,7 +984,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`.
*
* @see {Model#find}
* @see {@link Model#find}
*
* @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='=']
......@@ -986,6 +992,7 @@ class Sequelize {
* @method where
* @alias condition
* @since v2.0.0-dev3
* @memberof Sequelize
* @return {Sequelize.where}
*/
static where(attr, comparator, logic) {
......@@ -1029,15 +1036,14 @@ class Sequelize {
* ```
* 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 {Boolean} [options.autocommit]
* @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 {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}
* @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) {
if (typeof options === 'function') {
......@@ -1185,7 +1191,6 @@ Sequelize.prototype.validate = Sequelize.prototype.authenticate;
/**
* Sequelize version number.
* @property version
*/
Sequelize.version = require('../package.json').version;
......@@ -1193,8 +1198,7 @@ Sequelize.options = {hooks: {}};
/**
* A reference to Sequelize constructor from sequelize. Useful for accessing DataTypes, Errors etc.
* @property Sequelize
* @see {Sequelize}
* @see {@link Sequelize}
*/
Sequelize.prototype.Sequelize = Sequelize;
......@@ -1205,19 +1209,16 @@ Sequelize.prototype.Utils = Sequelize.Utils = Utils;
/**
* A handy reference to the bluebird Promise class
* @property Promise
*/
Sequelize.prototype.Promise = Sequelize.Promise = Promise;
/**
* Available query types for use with `sequelize.query`
* @property 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.
* @property Validator
* @see https://github.com/chriso/validator.js
*/
Sequelize.prototype.Validator = Sequelize.Validator = Validator;
......@@ -1230,24 +1231,21 @@ for (const dataType in DataTypes) {
/**
* A reference to the sequelize transaction class. Use this to access isolationLevels and types when creating a transaction
* @property Transaction
* @see {Transaction}
* @see {Sequelize#transaction}
* @see {@link Transaction}
* @see {@link Sequelize.transaction}
*/
Sequelize.prototype.Transaction = Sequelize.Transaction = Transaction;
/**
* A reference to the deferrable collection. Use this to access the different deferrable options.
* @property Deferrable
* @see {Deferrable}
* @see {Sequelize#transaction}
* @see {@link Transaction.Deferrable}
* @see {@link Sequelize#transaction}
*/
Sequelize.prototype.Deferrable = Sequelize.Deferrable = Deferrable;
/**
* A reference to the sequelize association class.
* @property Association
* @see {Association}
* @see {@link Association}
*/
Sequelize.prototype.Association = Sequelize.Association = Association;
......@@ -1265,7 +1263,6 @@ Hooks.applyTo(Sequelize);
/**
* A general error class
* @property Error
* @see {Errors#BaseError}
*/
Sequelize.prototype.Error = Sequelize.Error =
......@@ -1273,7 +1270,6 @@ Sequelize.prototype.Error = Sequelize.Error =
/**
* Emitted when a validation fails
* @property ValidationError
* @see {Errors#ValidationError}
*/
Sequelize.prototype.ValidationError = Sequelize.ValidationError =
......@@ -1281,7 +1277,6 @@ Sequelize.prototype.ValidationError = Sequelize.ValidationError =
/**
* Describes a validation error on an instance path
* @property ValidationErrorItem
* @see {Errors#ValidationErrorItem}
*/
Sequelize.prototype.ValidationErrorItem = Sequelize.ValidationErrorItem =
......
......@@ -170,20 +170,10 @@ class Transaction {
* Default to `DEFERRED` but you can override the default type by passing `options.transactionType` in `new Sequelize`.
* 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:
*
* ```js
* return sequelize.transaction({type: Sequelize.Transaction.EXCLUSIVE}, transaction => {
* return sequelize.transaction({type: Sequelize.Transaction.TYPES.EXCLUSIVE}, transaction => {
*
* // your transactions
*
......@@ -193,8 +183,9 @@ class Transaction {
* // do something with the err.
* });
* ```
*
* @property TYPES
* @property DEFFERED
* @property IMMEDIATE
* @property EXCLUSIVE
*/
Transaction.TYPES = {
DEFERRED: 'DEFERRED',
......@@ -206,21 +197,10 @@ Transaction.TYPES = {
* 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`.
*
* 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:
*
* ```js
* return sequelize.transaction({isolationLevel: Sequelize.Transaction.SERIALIZABLE}, transaction => {
* return sequelize.transaction({isolationLevel: Sequelize.Transaction.ISOLATION_LEVELS.SERIALIZABLE}, transaction => {
*
* // your transactions
*
......@@ -230,8 +210,10 @@ Transaction.TYPES = {
* // do something with the err.
* });
* ```
*
* @property ISOLATION_LEVELS
* @property READ_UNCOMMITTED
* @property READ_COMMITTED
* @property REPEATABLE_READ
* @property SERIALIZABLE
*/
Transaction.ISOLATION_LEVELS = {
READ_UNCOMMITTED: 'READ UNCOMMITTED',
......@@ -245,15 +227,6 @@ Transaction.ISOLATION_LEVELS = {
*
* ```js
* 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({
* where: ...,
* transaction: t1,
......@@ -275,7 +248,10 @@ Transaction.ISOLATION_LEVELS = {
* ```
* 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 = {
UPDATE: 'UPDATE',
......
......@@ -358,6 +358,7 @@ exports.toDefaultValue = toDefaultValue;
*
* @param {*} value Any default value.
* @return {boolean} yes / no.
* @private
*/
function defaultValueSchemable(value) {
if (typeof value === 'undefined') { return false; }
......@@ -449,6 +450,7 @@ exports.removeTicks = removeTicks;
/**
* 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.
* @private
*/
class Fn {
constructor(fn, args) {
......
......@@ -3,7 +3,10 @@
const util = require('util');
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) {
util.inherits(constructor, superConstructor); // Instance (prototype) methods
_.extend(constructor, superConstructor); // Static methods
......
......@@ -5,6 +5,7 @@
* It require a `context` for which messages will be printed.
*
* @module logging
* @private
*/
/* jshint -W030 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!