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

Commit 6fa22d6f by Nuno Sousa

Add hstore parsing during retrieval

1 parent 93b0daa1
...@@ -128,6 +128,14 @@ module.exports = (function() { ...@@ -128,6 +128,14 @@ module.exports = (function() {
}) })
} }
// Parse hstore fields.
// This cannot be done in the 'pg' lib because hstore is a UDT.
for (var key in rows[0]) {
if (!!this.callee && !!this.callee.rawAttributes && !!this.callee.rawAttributes[key] && !!this.callee.rawAttributes[key].type && this.callee.rawAttributes[key].type.toString() === DataTypes.HSTORE.toString()) {
rows[0][key] = hstore.parse(rows[0][key])
}
}
this.emit('success', this.send('handleSelectQuery', rows)) this.emit('success', this.send('handleSelectQuery', rows))
} }
} else if (this.send('isShowOrDescribeQuery')) { } else if (this.send('isShowOrDescribeQuery')) {
......
...@@ -254,7 +254,7 @@ if (dialect.match(/^postgres/)) { ...@@ -254,7 +254,7 @@ if (dialect.match(/^postgres/)) {
}) })
}) })
it("should handle hstore correctly", function(done) { it("should save hstore correctly", function(done) {
var self = this var self = this
this.User this.User
...@@ -273,6 +273,24 @@ if (dialect.match(/^postgres/)) { ...@@ -273,6 +273,24 @@ if (dialect.match(/^postgres/)) {
}) })
.error(console.log) .error(console.log)
}) })
it("should read hstore correctly", function(done) {
var self = this
var data = { username: 'user', email: ['foo@bar.com'], settings: { created: { test: '"value"' }}}
this.User
.create(data)
.success(function() {
// Check that the hstore fields are the same when retrieving the user
self.User.find({ where: { username: 'user' }})
.success(function(user) {
expect(user.settings).to.deep.equal(data.settings)
done()
})
})
.error(console.log)
})
}) })
describe('[POSTGRES] Unquoted identifiers', function() { describe('[POSTGRES] Unquoted identifiers', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!