Created
February 18, 2009 02:55
-
-
Save snusnu/66159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
gem 'dm-core', '=0.9.10' | |
require 'dm-core' | |
DataMapper::Logger.new(STDOUT, :debug) | |
DataMapper.setup(:default, 'sqlite3:memory:') | |
class Person | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
def greeting | |
"I'm a #{self.class} named #{name}" | |
end | |
end | |
puts "Person.storage_name = #{Person.storage_name}" | |
class Student < Person | |
def greeting | |
"Behold, #{super}" | |
end | |
end | |
puts "Student.storage_name = #{Student.storage_name}" | |
DataMapper.auto_migrate! | |
Person.create :name => "person" | |
Student.create :name => "student" | |
Person.all.each do |p| | |
puts "#{p.greeting} and my record is stored in #{p.class.storage_name}" | |
end | |
Student.all.each do |s| | |
puts "#{s.greeting} and my record is stored in #{s.class.storage_name}" | |
end | |
p = Person.first(:name => "person") | |
s = Student.first(:name => "student") | |
if p && s | |
puts "found Person #{p.name} by name" | |
puts "found Student #{s.name} by name" | |
end | |
# Person.storage_name = people | |
# Student.storage_name = people | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.003415) DROP TABLE IF EXISTS "people" | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.000050) PRAGMA table_info('people') | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.000031) SELECT sqlite_version(*) | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.002617) CREATE TABLE "people" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50)) | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.002917) INSERT INTO "people" ("name") VALUES ('person') | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.002364) INSERT INTO "people" ("name") VALUES ('student') | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.000201) SELECT "id", "name" FROM "people" ORDER BY "id" | |
# I'm a Person named person and my record is stored in people | |
# I'm a Person named student and my record is stored in people | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.000039) SELECT "id", "name" FROM "people" ORDER BY "id" | |
# Behold, I'm a Student named person and my record is stored in people | |
# Behold, I'm a Student named student and my record is stored in people | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.000043) SELECT "id", "name" FROM "people" WHERE ("name" = 'person') ORDER BY "id" LIMIT 1 | |
# Wed, 18 Feb 2009 03:07:42 GMT ~ debug ~ (0.000037) SELECT "id", "name" FROM "people" WHERE ("name" = 'student') ORDER BY "id" LIMIT 1 | |
# found Person person by name | |
# found Student student by name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment