Skip to content

davekrupinski/dm-mongo-adapter

This branch is 205 commits behind solnic/dm-mongo-adapter:master.

Folders and files

NameName
Last commit message
Last commit date
Jan 10, 2010
Mar 3, 2010
Jan 17, 2010
Feb 28, 2010
Jan 12, 2010
Jan 12, 2010
Jan 12, 2010
Jan 30, 2010
Feb 1, 2010
Jan 19, 2010
Feb 22, 2010
Feb 22, 2010

Repository files navigation

DataMapper MongoDB Adapter

Useful links:

Dependencies

Ruby gems

  • dm-core ~> 0.10.2

  • dm-aggregates ~> 0.10.2

  • mongo ~> 0.18.3

Install

gem install dm-mongo-adapter --pre

Synopsis

DataMapper.setup(:default,
  :adapter  => 'mongo',
  :database => 'my_mongo_db',
)

# Define embedded resources
class Address
  include DataMapper::Mongo::EmbeddedResource

  property :street, String
  property :city, String
  property :state, String
  property :postal_code, String
end

class Score
  include DataMapper::Mongo::EmbeddedResource

  property :grade, Float
  property :course_id, DBRef

  belongs_to :course
end

# Define top-level resources
class Student
  include DataMapper::Mongo::Resource

  property :id, ObjectID
  property :name, String
  property :age, Integer

  embeds 1, :address, :model => Address
  embeds n, :scores
end

class Course
  include DataMapper::Mongo::Resource

  property :id, ObjectID
  property :name, String
end

# No need to (auto_)migrate!
biology = Course.create(:name => "Biology")
english = Course.create(:name => "English")

# Nested attributes
student = Student.create(:name => "John", :age => "26",
  :address => { :street => "123 Main St.", :city => "New York", :state => "NY", :postal_code => "10014" },
  :scores  => [ { :grade => 4.0, :course_id => biology.id }, { :grade => 3.0, :course_id => english.id } ])

# Queries
Student.all(:age.gte => 20, :name => /oh/, :limit => 20, :order => [:age.asc])

# Reaching into embedded objects
Student.all(:"address.state" => "NY")

# Array and Hash as a property
class Zoo
  include DataMapper::Mongo::Resource

  property :id, ObjectID
  property :opening_hours, Hash
  property :animals, Array
end

Zoo.create(
  :opening_hours => { :weekend => '9am-8pm', :weekdays => '11am-8pm' },
  :animals       => [ "Marty", "Alex", "Gloria" ])

Zoo.all(:animals => 'Alex')

DataMapper plugins

Currently the adapter works with:

  1. dm-timestamps

  2. dm-validations

  3. dm-aggregates

  4. dm-pager

  5. dm-serializer

  6. dm-types

and expect more of course :)

Authors and contributors

The adapter has been originally written by Shane Hanna (shanna). Project is currently maintained by Piotr Solnica (solnic).

Contributors:

  • Anthony Williams (antw)

  • Lance Carlson (lancecarlson)

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 “Shane Hanna”, 2009-2010 “Piotr Solnica”. See LICENSE for details.

About

MongoDB DataMapper Adapter

Resources

License

Stars

Watchers

Forks

Packages

No packages published