New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nested-hstore

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nested-hstore

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Nested Hstore

Store nested hashes and other types in ActiveRecord hstores

Overview

Postgres hstores offer a number of benefits, but they don't natively support multi-level data. Nested Hstore adds this support to ActiveRecord, letting you treat an hstore like a NoSQL-like document.

Hstore functions are still supported at the root level.

It also lets you store data types other than hashes in an hstore. All of the following values will be returned verbatim:

class User < ActiveRecord::Base
  serialize :my_property, ActiveRecord::Coders::NestedHstore
end

# Nested hash
user.my_property = {
  'name' => 'Jane Doe',
  'comment_ids' => [34, 67, 82],
  'location' => {
    'id' => 15,
    'city' => 'San Francisco',
    'state' => 'CA'
  }
}

# Array
user.my_property = [34, 67, 82]

# Array of nested hashes
user.my_property = [
  {
    'id' => 15,
    'username' => 'janedoe'
  },
  {
    'id' => 16,
    'username' => 'johndoe'
  }
]

# Boolean
user.my_property = true

# Integer
user.my_property = 43

# Float
user.my_property = 43.1

# String
user.my_property = 'janedoe'

Installation

If you're using ActiveRecord 2.x or 3.x, set up activerecord-postgres-hstore if you haven't already. This isn't necessary for ActiveRecord 4.x.

Include it in your Gemfile:

gem 'nested-hstore'

Serialize each property using ActiveRecord::Coders::NestedHstore:

class User < ActiveRecord::Base
  serialize :my_property, ActiveRecord::Coders::NestedHstore
end

Testing

Nested Hstore is tested against ActiveRecord 3 and 4. If you'd like to submit a PR, please be sure to use Appraisal to test your changes in both contexts:

appraisal rspec

License

Nested Hstore is released under the MIT License. Please see the MIT-LICENSE file for details.

FAQs

Package last updated on 10 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc