Skip to content

kind of a bridge between using AR and a full blown schema-free db

License

Notifications You must be signed in to change notification settings

tribalvibes/serialized_attributes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Setup

Install the plugin into your Rails app.

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

About

kind of a bridge between using AR and a full blown schema-free db

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%