github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ninjudd / active_document

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (6)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (6)
    • v0.1.2
    • v0.0.6
    • v0.0.5
    • v0.0.4
    • v0.0.3
    • v0.0.2
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Active models in Berkeley DB. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

move deadlock test to bdb. use /tmp 
Justin Balthrop (author)
Tue Nov 24 13:32:00 -0800 2009
commit  39d5f016c3d41eb30de2e434be3c50aee0b2d632
tree    465543fc2df622255848878b0b77507f3c09976f
parent  ea8dd1a14478ad4153e92aee1dd30990030e5eac
active_document /
name age
history
message
file .gitignore Loading commit data...
file LICENSE
file README.rdoc
file Rakefile
file VERSION.yml
file active_document.gemspec
directory examples/
directory lib/
directory test/
README.rdoc

ActiveDocument

ActiveDocument is a persistent Model store built on Berkeley DB. It was inspired by ActiveRecord, and in some cases, it can be used as a drop-in replacement. The performance of ActiveDocument can exceed a traditional ORM for many applications, because the database is stored locally and all lookups must use a predefined index. Also, attributes do not have to be cast after they are read from the database like in ActiveRecord. Instead, Ruby objects are stored directly in Berkeley DB and loaded using Marshal, which makes loading objects much faster. For more information on the diffences between Berkeley DB and a relational Database, see (www.oracle.com/database/docs/Berkeley-DB-v-Relational.pdf).

Usage:

  require 'rubygems'
  require 'active_document'

  class User < ActiveDocument::Base
    path '/data/bdb'
    accessor :first_name, :last_name, :username, :email_address, :tags

    primary_key :username
    index_by [:last_name, :first_name]
    index_by :email_address, :unique => true
    index_by :tags, :multi_key => true
  end

  User.create(
    :first_name => 'John',
    :last_name  => 'Stewart',
    :username   => 'lefty',
    :email_address => 'john@thedailyshow.com',
    :tags => [:funny, :liberal]
  )

  User.create(
    :first_name => 'Martha',
    :last_name  => 'Stewart',
    :username   => 'helen',
    :email_address => 'martha@marthastewart.com',
    :tags => [:conservative, :convict]
  )

  User.create(
    :first_name => 'Stephen',
    :last_name  => 'Colbert',
    :username   => 'steve',
    :email_address => 'steve@thereport.com',
    :tags => [:conservative, :funny]
  )

  User.find('lefty').attributes
  => {"username"=>"lefty", "last_name"=>"Stewart", "email_address"=>"john@thedailyshow.com", "first_name"=>"John"}

  User.find_by_email_address("john@thedailyshow.com").username
  => "lefty"

  User.find_all_by_last_name("Stewart").collect {|u| u.first_name}
  => ["John", "Martha"]

  User.find_all_by_tag(:funny).collect {|u| u.username}
  => ["lefty", "steve"]

Complex finds:

Any find can take multiple keys, a key range, or multiple key ranges.

  User.create(
    :first_name => 'Will',
    :last_name  => 'Smith',
    :username   => 'legend',
    :email_address => 'will@smith.com',
    :tags => [:actor, :rapper]
  )

  User.find_all_by_last_name("Stewart", "Smith").collect {|u| u.username}
  => ["lefty", "helen", "legend"]

  User.find_all_by_last_name("Smith".."Stuart").collect {|u| u.username}
  => ["legend", "lefty", "helen"]

  User.find_all_by_last_name("Smith".."Stuart", "Colbert").collect {|u| u.username}
  => ["legend", "lefty", "helen", "steve"]

  User.find_all_by_last_name("Aardvark".."Daisy", "Smith".."Stuart").collect {|u| u.username}
  => ["steve", "legend", "lefty", "helen"]

Limit and Offset:

Any find can also take :limit, :offset, :page, and :per_page as options. These can be used for paginating large lists.

  User.find_all_by_username(:limit => 2).collect {|u| u.username}
  => ["helen", "lefty"]

  User.find_all_by_username(:limit => 2, :offset => 2).collect {|u| u.username}
  => ["legend", "steve"]

  User.find_all_by_username(:per_page => 2, :page => 1).collect {|u| u.username}
  => ["helen", "lefty"]

  User.find_all_by_username(:per_page => 2, :page => 2).collect {|u| u.username}
  => ["legend", "steve"]

Install:

  sudo gem install active_document -s http://gemcutter.org

Dependencies:

  • berkeley-db (4.8 recommended)
  • bdb
  • tuple

License:

Copyright © 2009 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server