Skip to content

Commit

Permalink
feat: add support for json columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Pon committed Jul 8, 2015
1 parent a4c01ad commit d6cf0ca
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ Loader.prototype.loadFixture = function(fixture, models) {
return Promise.all(promises);
};

var where = {};
var where = [];
Object.keys(Model.rawAttributes).forEach(function(k) {
if (data.hasOwnProperty(k) && (!fixture.keys || fixture.keys.indexOf(k) !== -1)) {
where[k] = data[k];
if (data.hasOwnProperty(k)) {
if (Model.rawAttributes[k].type.constructor.key === 'JSON') {
where.push([k + '::text = ?', JSON.stringify(data[k])]);
} else {
var and = {};
and[k] = data[k];
where.push(and);
}
}
});

Expand Down

3 comments on commit d6cf0ca

@domasx2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Can you tell me what problem were you having that these changes fix?
I tested with latest sequelize & postgres, and it looks like that sequelize generates correct sql to test json equality by default using json access operators

@ryanpon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

At the point I made these changes we were still running an older version of Sequelize that didn't properly support json comparisons. We're now on 3.9 so you're probably right that this isn't necessary anymore.

@domasx2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks!

Please sign in to comment.