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

Commit 16dac585 by Jan Aagaard Meier

More work on DAO factory api docs

1 parent 3097bfeb
......@@ -192,6 +192,7 @@ module.exports = (function() {
var newAttributes = {}
newAttributes[this.identifier] = { type: this.options.keyType || DataTypes.INTEGER }
Helpers.addForeignKeyConstraints(newAttributes[this.identifier], this.source, this.target, this.options)
Utils._.defaults(this.target.rawAttributes, newAttributes)
}
......
......@@ -7,7 +7,7 @@ var Utils = require("./utils")
module.exports = (function() {
/**
* 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:
* ```js
......@@ -18,7 +18,7 @@ module.exports = (function() {
* instance.getDataValue('field')
* ```
* 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
* @class DAO
*/
......@@ -210,7 +210,7 @@ module.exports = (function() {
, originalValue
if (typeof key === "object") {
values = keys
values = key
options = value
options || (options = {})
......@@ -683,16 +683,16 @@ module.exports = (function() {
/**
* 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
SET column = column + X
```
query. To get the correct value after an increment into the DAO you should do a reload.
```js
instance.increment('number') increment number by 1
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
```
* ```sql
* SET column = column + X
* ```
* query. To get the correct value after an increment into the DAO you should do a reload.
*
*```js
* instance.increment('number') increment number by 1
* 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
* ```
*
* @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
......@@ -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
```sql
SET column = column - X
```
query. To get the correct value after an decrement into the DAO you should do a reload.
```js
instance.decrement('number') decrement number by 1
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
```
* 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
* SET column = column - X
* ```
* query. To get the correct value after an decrement into the DAO you should do a reload.
*
* ```js
* instance.decrement('number') decrement number by 1
* 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
* ```
*
* @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
......@@ -790,6 +790,12 @@ instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, a
return this.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) {
var result = true
......@@ -804,19 +810,30 @@ instance.decrement({ answer: 42, tries: 1}, { by: 1 }) decrement answer by 42, a
return result
}
/**
* 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
*/
DAO.prototype.equalsOneOf = function(others) {
var result = false
, self = this
others.forEach(function(other) { result = result || self.equals(other) })
var self = this
return result
return _.any(others, function (other) {
return self.equals(other)
})
}
DAO.prototype.setValidators = function(attribute, validators) {
this.validators[attribute] = validators
}
/**
* Convert the DAO to a JSON representation. Proxies to `get`
*
* @see {DAO#get}
* @return {Object} The properties of the DAO
*/
DAO.prototype.toJSON = function() {
return this.get();
}
......
......@@ -154,12 +154,15 @@ module.exports = (function() {
/**
* A reference to Utils
* @property Utils
* @see {Utils}
*/
Sequelize.Utils = Utils
/**
* 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
* @property QueryTypes
* @see {Sequelize#query}
* @see {QueryTypes}
*/
......@@ -285,6 +288,8 @@ module.exports = (function() {
* @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.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.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
......
......@@ -26,6 +26,7 @@ var options = {
// Find constructor tags
javadoc.isConstructor = getTag(javadoc.raw.tags, 'constructor') !== undefined;
javadoc.isMixin = getTag(javadoc.raw.tags, 'mixin') !== undefined;
javadoc.isProperty = getTag(javadoc.raw.tags, 'property') !== undefined
javadoc.mixes = getTags(javadoc.raw.tags, 'mixes');
// Only show params without a dot in them (dots means attributes of object, so no need to clutter the co)
......@@ -37,6 +38,12 @@ var options = {
});
javadoc.paramStr = params.join(', ');
// Handle deprecation text
if (javadoc.deprecated) {
var deprecation = getTag(javadoc.raw.tags, 'deprecated')
javadoc.deprecated = deprecation.string
}
// Handle linking in comments
javadoc.see = getTags(javadoc.raw.tags, 'see');
javadoc.see.forEach(function (see, i, collection) {
......@@ -50,7 +57,7 @@ var options = {
_see[0] = _see[0].substring(1)
collection[i].url = _see[0]
collection[i].text = see.local
collection[i].text = see.local.replace(/{|}/g, '')
} else {
collection[i].url = false
collection[i].text = see.local
......@@ -70,7 +77,11 @@ var options = {
}
if (!javadoc.isClass) {
if (!javadoc.isProperty) {
docfile.members.push(javadoc.name + '(' + javadoc.paramStr + ')')
} else {
docfile.members.push(javadoc.name)
}
}
});
......
......@@ -28,12 +28,13 @@
<? if (comment.isClass) { ?>
### Members:
<? doc.members.forEach(function (member) { -?>
* <a href="#<?= member ?>"><?= member ?></a>
<? var link = member.replace(/\(.*?\)/, '') -?>
* <a href="#<?= link ?>"><?= member ?></a>
<? }) -?>
<? } ?>
<? if (comment.deprecated) { ?>
**Deprecated**
**Deprecated** <? if (typeof comment.deprecated === "string") { ?><?- comment.deprecated ?><? } ?>
<? } ?>
<? if (comment.author) { ?>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!