Skip to content

BrianTheCoder/dm-is-schemaless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inspired by bret.appspot.com/entry/how-friendfeed-uses-mysql I wanted to build a way to do that seamless. Hence this plugin.

It’s pretty straight forward. The bare minimum to use it is:

class Message
  include DataMapper::Resource

  is :schemaless

  # The following properties will be defined automatically
  # property :added_id, DataMapper::Types::Serial, :key => false
  # property :id, DataMapper::Types::UUID, :unique => true, :nullable => false, :index => true
  # property :updated, DataMapper::Types::EpochTime, :key => true, :index => true
  # property :body, DataMapper::Types::Json
end

Away you go! By default it creates keys and a few other fields. It adds a bit of method missing magic so any property you want automatically has name, name=, and name?. You should use these instead of accessing the body hash directly in order to keep nil indexes from being setup.

Declaring indexes. Just use the class level index_on method and supply a symbol. This will create the association and a table called <property>Index. It also creates an update hook to monitor the record when its save and handle creating/updating/destroying the index record.

class Message
  include DataMapper::Resource

  is :schemaless

  index_on :email
end

This is handled for you automatically. After you create an index on a property whenever you use that in a query it will transform the query to look it up on the index table instead. So internally here’s what happens.

# original query
Message.all(:email => 'test@gmail.com')
# transformed query
Message.all('email_index.email' => 'test@gmail.com')

This will also still support all of DM’s query operators.

Props to Dan Kubb for all his awesome work on DM and helping fix/refine this code.

File all bugs as issues on the project github.com/BrianTheCoder/dm-is-schemaless

About

Schemaless data in a traditional rdbms. Inspired by friendfeed

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages