No commit activity in last 3 years
No release in over 3 years
A bridge between using AR and a full blown schema-free db.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 3.3.0, >= 2.2.0
 Project Readme

SerializedAttributes

SerializedAttributes allows you to add an encoded hash to an ActiveRecord model. This is similar to the built-in ActiveRecord serialization, except that the field is converted to JSON, gzipped, and stored in a BLOB field. This uses the json gem which is much faster than YAML serialization. However, JSON is not nearly as flexible, so you're stuck with strings/integers/dates/etc.

Where possible, ActiveRecord compatible methods are generated so that a migration should be pretty simple. See unit tests for examples.

Some of the code and most of the ideas are taken from Heresy, a ruby implementation of how FriendFeed uses MySQL for schema-free storage.

Supports ActiveRecord 2.2 in ruby 1.8.7, and ActiveRecord 2.3-3.1 in ruby 1.9.3. See Travis CI to see if we support your version of ActiveRecord and ruby.

Setup

gem install serializable_attributes

Sorry for the confusion, but someone took the serialized_attributes gem name. I wouldn't mind giving it a completely new name before a "1.0" release though.

Usage

class Profile < ActiveRecord::Base
  # assumes #data serializes to raw_data blob field
  serialize_attributes do
    string  :title, :description
    integer :age
    float   :rank, :percentage
    time    :birthday
  end

  # Serializes #data to assumed raw_data blob field
  serialize_attributes :data do
    string  :title, :description
    integer :age
    float   :rank, :percentage
    time    :birthday
  end

  # set the blob field
  serialize_attributes :data, :blob => :serialized_field do
    string  :title, :description
    integer :age
    float   :rank, :percentage
    time    :birthday
  end
end