* // WHERE email like 'dan@sequelize.com%' AND access_level >= 42
* ```
*
* @param {Array|Object|String|null} option* The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments. To apply simple scopes, 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 {DAOFactory} A reference to the model, with the scope(s) applied. Calling scope again on the returned model will clear the previous scope.
* WHERE attr1 > 50 AND attr2 <= 45 AND attr3 IN (1,2,3) AND attr4 != 5
* ```
* Possible options are: `gt, gte, lt, lte, ne, between/.., nbetween/notbetween/!.., in, not, like, nlike/notlike`
*
* __Queries using OR__
* ```js
* Model.find({
* where: Sequelize.and(
* { name: 'a project' },
* Sequelize.or(
* { id: [1,2,3] },
* { id: { gt: 10 } }
* )
* )
* })
* ```
* ```sql
* WHERE name = 'a project' AND (id` IN (1,2,3) OR id > 10)
* ```
*
* @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 {Array<String>} [options.attributes] A list of the attributes that you want to select
* @param {Array<Object|DAOFactory>} [options.include] A list of associations to eagerly load. Supported is either { include: [ DaoFactory1, DaoFactory2, ...] } or { include: [ { model: DaoFactory1, as: 'Alias' } ] }. When using the object form, you can also specify `attributes`, `where` to limit the relations and their columns, and `include` to load further nested relations
* @param {String|Array|Sequelize.fn} [options.order] Specifies an ordering. If a string is provided, it will be esacped. Using an array, you can provide several columns / functions to order by. Each element can be further wrapped in a two-element array. The first element is the column / function to order by, the second is the direction. For example: `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not.
* @param {Number} [options.limit]
* @param {Number} [options.offset]
* @param {Object} [queryOptions] set the query options, e.g. raw, specifying that you want raw data instead of built DAOs. See sequelize.query for options
* @param {Transaction} [queryOptions.transaction]
* @param {Boolean} [queryOptions.raw] Returns the results as raw JS objects instead of DAO instances
*
* @see {Sequelize#query}
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, an array of DAOs will be returned to the success listener
* @param {Object|Number} options A hush of options to describe the scope of the search, or a number to search by id.
* @param {Object|Number} [options] A hash of options to describe the scope of the search, or a number to search by id.
* @param {Object} [options.where]
* @param {Object} [queryOptions]
* @param {Array<String>} [options.attributes] A list of the attributes that you want to select
* @param {Array<Object|DAOFactory>} [options.include] A list of associations which shall get eagerly loaded. Supported is either { include: [ DaoFactory1, DaoFactory2, ...] } or { include: [ { daoFactory: DaoFactory1, as: 'Alias' } ] }.
* @param {String|Array} [options.order]
* @param {Number} [options.limit]
* @param {Number} [options.offset]
* @param {Object} queryOptions set the query options, e.g. raw, specifying that you want raw data instead of built DAOs. See sequelize.query for options
* @param {Transaction} queryOptions.transaction
*
*
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, a DAO will be return to the sucess listener
* @see {DAOFactory#findAll} for an explanation of options and queryOptions
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, a DAO will be returned to the success listener
* Run an aggregation method on the specified field
*
* @param {String} field The field to aggregate over. Can be a field name or *
* @param {String} aggregateFunction The function to use for aggregation, e.g. sum, max etc.
* @param {Object} [options] Query options. See sequelize.query for full options
* @param {DataType|String} [options.dataType] The type of the result. If field is a field in the DAO, the default will be the type of that field, otherwise defaults to float.
*
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, the result of the aggregation function will be returned to the success listener
* Find all the rows matching your query, within a specified offset / limit, and get the total number of rows matching your query. This is very usefull for paging
*
* ```js
* Model.findAndCountAll({
* where: ...,
* limit: 12,
* offset: 12
* }).success(function (result) {
// result.rows will contain rows 13 through 24, while result.count will return the total number of rows that matched your query
* })
* ```
* @param {Object} [findOptions]
* @param {Object} [queryOptions]
*
* @see {DAOFactory#findAll} for a specification of find and query options
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, an object containing rows and count will be returned
* Find a row that matches the query, or build (but don't save) the row if none is found.
*
* @param {Object} where A hash of search attributes. Note that this method differs from finders, in that the syntax is { attr1: 42 } and NOT { where: { attr1: 42}}. This is subject to change in 2.0
* @param {Object} [defaults] Default values to use if building a new instance
* @param {Object} [options] Options passed to the find call
* @deprecated The syntax is due for change, in order to make `where` more consistent with the rest of the API
*
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, the DAO will be return to the success listener
* Find a row that matches the query, or build and save the row if none is found
*
* @param {Object} where A hash of search attributes. Note that this method differs from finders, in that the syntax is { attr1: 42 } and NOT { where: { attr1: 42}}. This is subject to change in 2.0
* @param {Object} [defaults] Default values to use if creating a new instance
* @param {Object} [options] Options passed to the find and create calls
* @deprecated The syntax is due for change, in order to make `where` more consistent with the rest of the API
*
* @return {EventEmitter} Fires `success`, `error` and `sql`. Upon success, the DAO will be return to the success listener
* @return {EventEmitter} Fires `success`, `error` and `sql`. The success` handler is not passed any arguments. To obtain DAOs for the newly created values, you will need to query for them again. This is because MySQL and SQLite do not make it easy to obtain back automatically generated IDs and other default values in a way that can be mapped to multiple records
* @return {EventEmitter} Fires `success`, `error` and `sql`. The success` handler is not passed any arguments. To obtain DAOs for the newly created values, you will need to query for them again. This is because MySQL and SQLite do not make it easy to obtain back automatically generated IDs and other default values in a way that can be mapped to multiple records
* @param {Object} where Options to describe the scope of the search.
* @param {Object} [where] Options to describe the scope of the search.
* @param {Object} options:
* @param {Object} [options]
* @param {Boolean} options.hooks If set to true, destroy will find all records within the where parameter and will execute before/afterDestroy hooks on each row
* @param {Boolean} [options.hooks] If set to true, destroy will find all records within the where parameter and will execute before/afterDestroy hooks on each row
* @param {Number} options.limit How many rows to delete
* @param {Number} [options.limit] How many rows to delete
* @param {Boolean} options.truncate If set to true, dialects that support it will use TRUNCATE instead of DELETE FROM. If a table is truncated the where and limit options are ignored
* @param {Boolean} [options.truncate] If set to true, dialects that support it will use TRUNCATE instead of DELETE FROM. If a table is truncated the where and limit options are ignored
*
*
* @return {EventEmitter} Fires `success`, `error` and `sql`.
* @return {EventEmitter} Fires `success`, `error` and `sql`.
* A proxy to the node-sql query builder, which allows you to build your query through a chain of method calls. The returned instance already has all the fields defined on the model. If you have a user model with a column
* This class represents an single instance, a database column. You might see it referred to as both DAO and instance.
* This class represents an single instance, a database row. You might see it referred to as both DAO and instance.
*
*
* DAO instances operate with the concept of a `dataValues` property, which stores the actual values represented by this DAO. By default, the values from dataValues can also be accessed directly from the DAO, that is:
* DAO instances operate with the concept of a `dataValues` property, which stores the actual values represented by this DAO. By default, the values from dataValues can also be accessed directly from the DAO, that is:
* ```js
* ```js
...
@@ -18,7 +18,7 @@ module.exports = (function() {
...
@@ -18,7 +18,7 @@ module.exports = (function() {
* instance.getDataValue('field')
* instance.getDataValue('field')
* ```
* ```
* 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`.
*
* @see {Sequelize#define} Sequelize#define for more information about getters and setters
* @see {Sequelize#define} Sequelize#define for more information about getters and setters
* Increment the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the DAO. The increment is done using a
* Increment the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the DAO. The increment is done using a
```sql
* ```sql
SET column = column + X
* SET column = column + X
```
* ```
query. To get the correct value after an increment into the DAO you should do a reload.
* query. To get the correct value after an increment into the DAO you should do a reload.
*
```js
*```js
instance.increment('number') increment number by 1
* instance.increment('number') increment number by 1
instance.increment(['number', 'count'], { by: 2 }) increment number and count by 2
* instance.increment(['number', 'count'], { by: 2 }) increment number and count by 2
instance.increment({ answer: 42, tries: 1}, { by: 1 }) increment answer by 42, and tries by 1. `by` is ignore, since each column has its own value
* instance.increment({ answer: 42, tries: 1}, { by: 1 }) increment answer by 42, and tries by 1. `by` is ignore, since each column has its own value
```
* ```
*
*
* @see {DAO#reload}
* @see {DAO#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
...
@@ -742,17 +742,17 @@ instance.increment({ answer: 42, tries: 1}, { by: 1 }) increment answer by 42, a
...
@@ -742,17 +742,17 @@ instance.increment({ answer: 42, tries: 1}, { by: 1 }) increment answer by 42, a
}
}
/**
/**
* Increment the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the DAO. The decrement is done using a
* Decrement the value of one or more columns. This is done in the database, which means it does not use the values currently stored on the DAO. The decrement is done using a
```sql
* ```sql
SET column = column - X
* SET column = column - X
```
* ```
query. To get the correct value after an decrement into the DAO you should do a reload.
* query. To get the correct value after an decrement into the DAO you should do a reload.
*
```js
* ```js
instance.decrement('number') decrement number by 1
* instance.decrement('number') decrement number by 1
instance.decrement(['number', 'count'], { by: 2 }) decrement number and count by 2
* instance.decrement(['number', 'count'], { by: 2 }) decrement number and count by 2
instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, and tries by 1. `by` is ignore, since each column has its own value
* instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, and tries by 1. `by` is ignore, since each column has its own value
```
* ```
*
*
* @see {DAO#reload}
* @see {DAO#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
...
@@ -790,6 +790,12 @@ instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, a
...
@@ -790,6 +790,12 @@ instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, a
returnthis.increment(fields,countOrOptions)
returnthis.increment(fields,countOrOptions)
}
}
/**
* Check whether all values of this and `other` DAO are the same
*
* @param {DAO} other
* @return {Boolean} true if the two DAOs have the same values
*/
DAO.prototype.equals=function(other){
DAO.prototype.equals=function(other){
varresult=true
varresult=true
...
@@ -804,19 +810,30 @@ instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, a
...
@@ -804,19 +810,30 @@ instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, a
returnresult
returnresult
}
}
/**
* Check if this is eqaul to one of `others` by calling equals
*
* @param {Array} others
* @return {Boolean} true if at least one of the DAOs in others has the same values as this
* An object of different query types. This is used when doing raw queries (sequlize.query). If no type is provided to .query, sequelize will try to guess the correct type based on your SQL. This might not always work if you query is formatted in a special way
* An object of different query types. This is used when doing raw queries (sequlize.query). If no type is provided to .query, sequelize will try to guess the correct type based on your SQL. This might not always work if you query is formatted in a special way
* @param {Function} [attributes.column.set] Provide a custom setter for this column. Use this.getDataValue(String) and this.setDataValue(String, Value) to manipulate the underlying values.
* @param {Function} [attributes.column.set] Provide a custom setter for this column. Use this.getDataValue(String) and this.setDataValue(String, Value) to manipulate the underlying values.
* @param {Object} [options] These options are merged with the options provided to the Sequelize constructor
* @param {Object} [options] These options are merged with the options provided to the Sequelize constructor
* @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 `DAOFactory.scope` for more information about how scopes are defined, and what you can do with them
* @param {Boolean} [options.omitNull] Don't persits null values. This means that all columns with null values will not be saved
* @param {Boolean} [options.omitNull] Don't persits null values. This means that all columns with null values will not be saved
* @param {Boolean} [options.timestamps=true] Handle createdAt and updatedAt timestamps
* @param {Boolean} [options.timestamps=true] Handle createdAt and updatedAt timestamps
* @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