- Allow store/retrieve deep ruby hash into postgresql table using hstore field.
- Allow efficient search and indexing by this fields
Add this line to your application's Gemfile:
gem 'hstored_document'
And then execute:
$ bundle
Or install it yourself as:
$ gem install hstored_document
create table mydocs (id uuid, attributes hstore);
class MyDocStorage < HstoredDocument
end
id = UUID.generate
doc = {id: id, prop1: 'val1', prop2: [1, 2, 3], prop3: [{nprop: 'nval'}]}
store = MyDocStorage
store.store(doc)
store.find(id).should == doc
store.where('doc.prop2' => 3, prop1: 'val1')
store.where('doc.prop3.nprop' => 'nval')
store.store(doc.merge(propr1: 'changed1'))
store.find(id)[:prop1].should == 'changed1'
store.delete(id)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request