Skip to content

Commit

Permalink
Add support for 2233 for pg and sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
janmeier committed Sep 13, 2014
1 parent 95af31e commit 0b9ddfa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/dialects/postgres/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ module.exports = (function() {
var match;

switch (err.code) {
case '23503':
match = err.message.match(/violates foreign key constraint \"(.+?)\" on table \"(.+?)\"/);
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
index: match[1],
table: match[2],
parent: err
});
case '23505':
match = err.detail.match(/Key \((.*?)\)=\((.*?)\) already exists/);

Expand Down
7 changes: 7 additions & 0 deletions lib/dialects/sqlite/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ module.exports = (function() {
});
}

match = err.message.match(/FOREIGN KEY constraint failed/);
if (match !== null) {
return new sequelizeErrors.ForeignKeyConstraintError({
parent :err
});
}

return err;
case 'SQLITE_BUSY':
return new sequelizeErrors.TimeoutError(err);
Expand Down
1 change: 1 addition & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ error.ForeignKeyConstraintError = function (options) {

this.message = options.message;
this.fields = options.fields;
this.table = options.table;
this.value = options.value;
this.index = options.index;
};
Expand Down

0 comments on commit 0b9ddfa

Please sign in to comment.