· 8 years ago · Apr 26, 2018, 11:32 PM
1%w[dm-core dm-ar-finders data_objects do_sqlite3].each{|g| gem g}
2require 'dm-core'
3require 'dm-ar-finders'
4DataMapper.setup(:default, 'sqlite3::memory:')
5DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, :debug)
6
7class Bug
8 include DataMapper::Resource
9 property :id, Serial
10 property :name, String
11 property :bugged_field, String, :field => "bugg"
12 property :not_a_bug, String
13end
14
15DataMapper.auto_migrate!
16
17Bug.create(:name =>"BugName1", :bugged_field => "BuggedField1", :not_a_bug => "Not a bug1")
18
19p Bug.find_by_sql("SELECT * FROM bugs")
20
21=begin
22Sat, 26 Dec 2009 12:45:08 GMT ~ debug ~ (0.000037) SELECT sqlite_version(*)
23Sat, 26 Dec 2009 12:45:08 GMT ~ debug ~ (0.000104) DROP TABLE IF EXISTS "bugs"
24Sat, 26 Dec 2009 12:45:08 GMT ~ debug ~ (0.000011) PRAGMA table_info("bugs")
25Sat, 26 Dec 2009 12:45:08 GMT ~ debug ~ (0.000370) CREATE TABLE "bugs" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50), "bugg" VARCHAR(50), "not_a_bug" VARCHAR(50))
26Sat, 26 Dec 2009 12:45:08 GMT ~ debug ~ (0.000042) INSERT INTO "bugs" ("name", "bugg", "not_a_bug") VALUES ('BugName1', 'BuggedField1', 'Not a bug1')
27Sat, 26 Dec 2009 12:45:08 GMT ~ debug ~ (0.000028) SELECT * FROM bugs
28[#<Bug @id=1 @name="BugName1" @bugged_field=nil @not_a_bug="BuggedField1">]
29=end