· 8 years ago · Mar 09, 2018, 12:50 AM
1require 'rubygems'
2
3gem 'addressable', '2.0.1'
4gem 'data_objects', '0.10.0'
5gem 'do_sqlite3', '0.10.0'
6gem 'dm-core', '0.10.0'
7require 'dm-core'
8
9class Post
10 include DataMapper::Resource
11
12 def self.default_repository_name
13 :post
14 end
15
16 property :id, Serial
17 property :title, String
18end
19
20DataMapper.setup(:post, "sqlite3::memory:")
21DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, 0)
22DataMapper.auto_migrate!
23
24
25post = Post.create(:title => 'Post 1')
26post_2 = Post.create(:title => 'Post 2')
27
28p Post.all(:id => [post.id, post_2.id])
29p Post.all(:id.not => [])
30
31# STDOUT
32# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.000067) SELECT sqlite_version(*)
33# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.002203) DROP TABLE IF EXISTS "posts"
34# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.000038) PRAGMA table_info("posts")
35# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.000507) CREATE TABLE "posts" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "title" VARCHAR(50))
36# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.000092) INSERT INTO "posts" ("title") VALUES ('Post 1')
37# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.000076) INSERT INTO "posts" ("title") VALUES ('Post 2')
38# Fri, 26 Jun 2009 05:54:02 GMT ~ debug ~ (0.000085) SELECT "id", "title" FROM "posts" WHERE "id" IN (1, 2) ORDER BY "id"
39# [#<Post @id=1 @title="Post 1">, #<Post @id=2 @title="Post 2">]
40# /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:757:in `assert_valid_conditions': Cannot use 'not' operator with a bind value that is >
41# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:742:in `each'
42# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:742:in `assert_valid_conditions'
43# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:669:in `assert_valid_options'
44# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:659:in `each'
45# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:659:in `assert_valid_options'
46# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:601:in `initialize'
47# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:307:in `update'
48# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/query.rb:323:in `merge'
49# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:612:in `scoped_query'
50# from /home/shingara/.gem/ruby/1.8/gems/dm-core-0.10.0/lib/dm-core/model.rb:237:in `all'
51# from empty_search.rb:29
52#