CuteKV – based at Ruby for object-key/value map
Main features
-
Independent Object Storage
Through backend_configure to appoint storage location
class User < ActiveObject::Base backend_configure :TT,“127.0.0.1:1987” end
-
Customize define persistent properties you can assign persitent properties by <t>assign</t> method,and set default value for each property.
class User
include CuteKV::Document
backend_configure :TT,“127.0.0.1:1987” assign :name,:email, :gender=>‘male’, :age=>25 end
==Object's associations
Using CuteKV::associations module, we can description associations between objects
class User
include CuteKV::Document
backend_configure :TT,“127.0.0.1:1987” assign :name,:email, :gender=>‘male’, :age=>25 end
CuteKV::associations::map(User=>:icon, Icon=>:user) #=>user has one icon and icon belongs to one user
CuteKV::associations::map(User=>:friends) #=>user has many friends
class Icon < ActiveObject::Base
include CuteKV::Document
backend_configure :TT,“127.0.0.1:1987” assign :content end
==Validations
now CuteKV support validations by a simple method <t>validate</t> from CuteKV::Validations module
I just keep it simple or i will improve it to approach activerecord's validations
class User
include CuteKV::Document
incude CuteKV::Validations backend_configure :TT,“127.0.0.1:1987” assign :name,:email, :gender=>‘male’, :age=>25 validate :name_presence_valid
def name_presence_valid errors.add(:name, “name should not blank”) if self.name.blank? end
end
@jim = User.create() @jim.save #=>nil User.find(@jim.id) #=>nil @jim.errors_message_on(:name) #=>“name should not blank”
==Index
class User
include CuteKV::Document
backend_configure :TT,“127.0.0.1:1987” assign :name,:email, :gender=>‘male’, :age=>25 end
@jim = User.create(:name=>"jim", :email=>"[email protected]")
@aaron = User.create(:name=>"aaron", :email=>"[email protected]")
@jack= User.create(:name=>"jack", :email=>"[email protected]")
@lucy = User.create(:name=>"lucy", :email=>"[email protected]")
Useing CuteKV::Indexer module, you can build index for object, just like:
CuteKV::Indexer::map(User=>[:name, :email, :age])
then,
User.indexes << @jim
User.indexes << @aaron
User.indexes << @lucy
User.find_all_by_name("jim") #=>@jim
User.find_all_by_age(25) #=>@jim, @aaron, @lucy, @jack
== Supoort multiple database
CuteKV using adapter to connect database.now backend support:TokyoCabinet/TokyoTyrant/LightCloud。
Using in rails
in environment.rb, you will add
require ‘cutekv’