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

Commit 18e808ec by Mick Hansen

Merge branch 'bug/postgres-array-of-json' of https://github.com/bulkan/sequelize…

… into bulkan-bug/postgres-array-of-json
2 parents 02290ce8 26844be8
Showing with 29 additions and 2 deletions
...@@ -20,7 +20,11 @@ if (dialect.match(/^postgres/)) { ...@@ -20,7 +20,11 @@ if (dialect.match(/^postgres/)) {
settings: DataTypes.HSTORE, settings: DataTypes.HSTORE,
document: { type: DataTypes.HSTORE, defaultValue: { default: "'value'" } }, document: { type: DataTypes.HSTORE, defaultValue: { default: "'value'" } },
phones: DataTypes.ARRAY(DataTypes.HSTORE), phones: DataTypes.ARRAY(DataTypes.HSTORE),
emergency_contact: DataTypes.JSON emergency_contact: DataTypes.JSON,
friends: {
type: DataTypes.ARRAY(DataTypes.JSON),
defaultValue: []
}
}); });
this.User.sync({ force: true }).success(function() { this.User.sync({ force: true }).success(function() {
done(); done();
...@@ -34,11 +38,34 @@ if (dialect.match(/^postgres/)) { ...@@ -34,11 +38,34 @@ if (dialect.match(/^postgres/)) {
it('should be able to search within an array', function(done) { it('should be able to search within an array', function(done) {
this.User.all({where: {email: ['hello', 'world']}}).on('sql', function(sql) { this.User.all({where: {email: ['hello', 'world']}}).on('sql', function(sql) {
expect(sql).to.equal('SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];'); expect(sql).to.equal('SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "friends", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];');
done(); done();
}); });
}); });
it('should be able update a field with type ARRAY(JSON)', function(){
return this.User.create({
username: 'bob', email: ['myemail@email.com']
})
.then(function(userInstance){
expect(userInstance.friends).to.have.length(0);
return userInstance.updateAttributes({
friends: [{
name: 'John Smythe'
}],
//friends: [JSON.stringify({
//name: 'John Smythe'
//})]
});
})
.get('friends')
.tap(function(friends){
expect(friends).to.have.length(1);
});
});
it('should be able to find a record while searching in an array', function(done) { it('should be able to find a record while searching in an array', function(done) {
var self = this; var self = this;
this.User.bulkCreate([ this.User.bulkCreate([
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!