Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Rails
  3. activerecord-typedstore

activerecord-typedstore

MITRuby

Adds type definitions, validations, and default values to ActiveRecord::Store for structured JSON/HStore columns in Rails.

GitHubGitHub
467 stars58 forks0 contributors

What is activerecord-typedstore?

ActiveRecord::TypedStore is a Ruby gem that extends ActiveRecord::Store with type definitions, validations, and default values for JSON or HStore database columns in Rails applications. It provides type safety and ActiveModel attribute behavior while maintaining the flexibility of schema-less storage, eliminating the need for migrations when adding or removing attributes.

Target Audience

Rails developers using PostgreSQL JSON/HStore columns or similar schema-less storage who need type safety, validations, and default values without sacrificing flexibility.

Value Proposition

Developers choose ActiveRecord::TypedStore because it brings ActiveRecord's familiar migration syntax and type casting to schema-less storage, reducing bugs with type safety while keeping the agility of not requiring database migrations for attribute changes.

Overview

ActiveRecord::Store but with type definition

Use Cases

Best For

  • Adding type safety to existing ActiveRecord::Store implementations
  • Storing structured settings or preferences in JSON/HStore columns with validation
  • Gradually evolving schema without database migrations
  • Building flexible data models with typed attributes in Rails
  • Using PostgreSQL JSON columns with ActiveRecord attribute behavior
  • Implementing feature flags or configuration with type constraints

Not Ideal For

  • Applications requiring complex SQL queries on store attributes without relying on PostgreSQL JSON/HStore types
  • Projects where database-level type constraints and migrations are essential for data integrity and audit trails
  • Teams using databases with limited or no JSON/HStore support, such as older MySQL versions

Pros & Cons

Pros

Seamless Rails Integration

Mimics ActiveRecord migration syntax, making it intuitive for Rails developers to define typed attributes without a new DSL, as shown in the usage example with familiar methods like s.string and s.boolean.

Comprehensive Type Safety

Supports boolean, string, integer, datetime, array, and custom types with automatic type casting, ensuring data consistency as demonstrated in the example where 'age' is cast from string to integer.

Full ActiveModel Support

Integrates with ActiveModel for validations, change tracking, and attribute methods like *_changed?, allowing developers to use Rails patterns, such as validating age with presence true.

Flexible Storage Options

Works with any custom coder, JSON columns, or Postgres HStore, providing adaptability to different database setups as detailed in the serialization methods section.

Cons

Query Limitations

As admitted in the README, attributes cannot be queried in SQL unless using JSON or Postgres HStore types, which restricts database-level data manipulation and indexing.

HStore Constraints

When using Postgres HStore, array attributes don't work and any types are converted to strings, limiting functionality as explicitly stated in the HStore limitations section.

Application-Level Overhead

Type casting and validations are handled at the application level, which could introduce performance overhead compared to database-native type constraints, especially for large-scale operations.

Frequently Asked Questions

Quick Stats

Stars467
Forks58
Contributors0
Open Issues15
Last commit2 years ago
CreatedSince 2013

Tags

#database#rails-gem#type-safety#activemodel#activerecord#ruby-on-rails

Built With

R
Rails
R
Ruby
A
ActiveRecord

Included in

Rails3.9k
Auto-fetched 11 hours ago

Related Projects

devisedevise

Flexible authentication solution for Rails with Warden.

Stars24,355
Forks5,473
Last commit2 months ago
spreespree

Open Source eCommerce Platform for B2B, Marketplace, and Enterprise. REST API, TypeScript SDK, and production-ready Next.js storefront. Self-host it. Own your stack. No vendor lock-in. Zero platform fees.

Stars15,672
Forks5,296
Last commit16 hours ago
activeadminactiveadmin

The administration framework for Ruby on Rails applications.

Stars9,708
Forks3,326
Last commit1 day ago
CarrierwaveCarrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks

Stars8,775
Forks1,648
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub