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

Commit d51cc90e by Jan Aagaard Meier

Fix indentation in formatError and fix docs for findOrCreate. Use .get instead o…

…f direct access in findOrCreate
1 parent 023bab43
...@@ -61,9 +61,10 @@ module.exports = (function() { ...@@ -61,9 +61,10 @@ module.exports = (function() {
value: match[1], value: match[1],
parent: err parent: err
}); });
}
default:
return new sequelizeErrors.DatabaseError(err); return new sequelizeErrors.DatabaseError(err);
}
}; };
Query.prototype.isShowIndexesQuery = function () { Query.prototype.isShowIndexesQuery = function () {
......
...@@ -235,9 +235,10 @@ module.exports = (function() { ...@@ -235,9 +235,10 @@ module.exports = (function() {
index: null, index: null,
parent: err parent: err
}); });
}
default:
return new sequelizeErrors.DatabaseError(err); return new sequelizeErrors.DatabaseError(err);
}
}; };
Query.prototype.isShowIndexesQuery = function () { Query.prototype.isShowIndexesQuery = function () {
......
...@@ -200,9 +200,10 @@ module.exports = (function() { ...@@ -200,9 +200,10 @@ module.exports = (function() {
return err; return err;
case 'SQLITE_BUSY': case 'SQLITE_BUSY':
return new sequelizeErrors.TimeoutError(err); return new sequelizeErrors.TimeoutError(err);
}
default:
return new sequelizeErrors.DatabaseError(err); return new sequelizeErrors.DatabaseError(err);
}
}; };
Query.prototype.handleShowIndexesQuery = function (data) { Query.prototype.handleShowIndexesQuery = function (data) {
......
...@@ -1081,8 +1081,8 @@ module.exports = (function() { ...@@ -1081,8 +1081,8 @@ module.exports = (function() {
* However, it is not always possible to handle this case in SQLite, specifically if one transaction inserts and another tries to select before the first one has comitted. In this case, an instance of sequelize.TimeoutError will be thrown instead. * However, it is not always possible to handle this case in SQLite, specifically if one transaction inserts and another tries to select before the first one has comitted. In this case, an instance of sequelize.TimeoutError will be thrown instead.
* If a transaction is created, a savepoint will be created instead, and any unique constraint violation will be handled internally. * If a transaction is created, a savepoint will be created instead, and any unique constraint violation will be handled internally.
* *
* @param {Object} [options] * @param {Object} options
* @param {Object} [options.where] 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} options.where where A hash of search attributes.
* @param {Object} [options.defaults] Default values to use if creating a new instance * @param {Object} [options.defaults] Default values to use if creating a new instance
* @param {Object} [queryOptions] Options passed to the find and create calls * @param {Object} [queryOptions] Options passed to the find and create calls
* *
...@@ -1095,8 +1095,8 @@ module.exports = (function() { ...@@ -1095,8 +1095,8 @@ module.exports = (function() {
queryOptions = queryOptions ? Utils._.clone(queryOptions) : {}; queryOptions = queryOptions ? Utils._.clone(queryOptions) : {};
if (!options.where) { if (!options || !options.where) {
throw new Error('Missing where attribute in the first parameter passed to findOrCreate. Please note that the API has changed, and is now options (an object with where and defaults keys), queryOptions (transaction etc.)'); throw new Error('Missing where attribute in the options parameter passed to findOrCreate. Please note that the API has changed, and is now options (an object with where and defaults keys), queryOptions (transaction etc.)');
} }
// Create a transaction or a savepoint, depending on whether a transaction was passed in // Create a transaction or a savepoint, depending on whether a transaction was passed in
...@@ -1123,7 +1123,7 @@ module.exports = (function() { ...@@ -1123,7 +1123,7 @@ module.exports = (function() {
queryOptions.exception = 'WHEN unique_violation THEN RETURN QUERY SELECT * FROM <%= table %> WHERE 1 <> 1;'; queryOptions.exception = 'WHEN unique_violation THEN RETURN QUERY SELECT * FROM <%= table %> WHERE 1 <> 1;';
return self.create(values, queryOptions).bind(this).then(function(instance) { return self.create(values, queryOptions).bind(this).then(function(instance) {
if (instance[self.primaryKeyAttribute] === null) { if (instance.get(self.primaryKeyAttribute, { raw: true }) === null) {
// If the query returned an empty result for the primary key, we know that this was actually a unique constraint violation // If the query returned an empty result for the primary key, we know that this was actually a unique constraint violation
throw new self.sequelize.UniqueConstraintError(); throw new self.sequelize.UniqueConstraintError();
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!