Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created Jun 21, 2009
Embed
What would you like to do?
#!ruby
require 'rubygems'
gem 'dm-core', '=0.10.0'
# gem 'dm-core', '=0.9.11'
require 'dm-core'
DataMapper::Logger.new(STDOUT, :all)
DataMapper.setup(:default, "mysql://root:password@localhost/db_testing")
class Car
include DataMapper::Resource
property :id, Serial
property :brand, String
property :year, Integer
property :color, String
end
Car.auto_migrate!
Car.create(:brand => 'Honda', :year => 2008, :color => 'blue')
Car.create(:brand => 'Toyota', :year => 2008, :color => 'red')
p Car.all(:brand => 'Toyota')
p Car.all(:year => 2008)
p Car.all(:year => 2008, :color.not => 'blue').all(:conditions => ['brand = ? OR brand = ?', 'Toyota', 'Honda'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment