-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
57 lines (49 loc) · 1.62 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require_relative 'lib/mongorb'
require 'ffaker'
DataMapper::Logger.new $stdout, :debug
DataMapper.setup :default, 'mongodb://localhost/test'
class Person
include Mongorb::Document
property :name, String, :allow_blank => false
property :birthday, Date
property :height, Integer
end
person = Person.new(
:name => Faker::Name.name,
:height => rand(80) + 140
)
puts "[SAVE] #{person.save}"
def find_people(conditions = {})
puts
puts Person.all(conditions).map &:attributes
end
=begin
find_people
find_people :name => Faker::Name.name
find_people :name => Faker::Name.name, :height => 200
find_people :height.gt => 200
find_people :height.gte => 210
find_people :height.lt => 160
find_people :height.lte => 150
find_people :height.ne => 213
find_people :name => [Faker::Name.name, Faker::Name.name, Faker::Name.name]
find_people :height.nin => (170..210).to_a
find_people :height.mod => [2, 1]
find_people :height.size => 200
find_people :height.exists => true
find_people :height.exists => false
find_people :birthday.exists => 1
find_people :birthday.exists => 0
find_people :name => /^b/
find_people :name => /^b/i
find_people :height.not => 200
puts Person.count :height.gt => 210
Person.all(:height.gt => 210).update :height => 210 + rand(10)
Person.all(:height.gt => 210).destroy
puts 'UNION'
puts (Person.all(:height.lt => 160) | Person.all(:height.gt => 210)).map &:attributes
puts "INTERSECTION"
puts (Person.all(:name => /^Mr\./) & (Person.all(:height.lt => 160) | Person.all(:height.gt => 210))).map &:attributes
=end
Person.all(:height.gt => 210).update! :height => 210 + rand(10)
Person.all(:height.gt => 210).destroy!