-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrethink_runner.rb
More file actions
51 lines (41 loc) · 1.05 KB
/
rethink_runner.rb
File metadata and controls
51 lines (41 loc) · 1.05 KB
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
require './runner'
require 'rethinkdb'
include RethinkDB::Shortcuts
class RethinkRunner < Runner
@@DB_NAME = 'rethink_benchmarks'
def initialize
super
@conn = r.connect(:host => 'localhost',
:port => 28015,
:db => @@DB_NAME)
end
def print_version
puts '* ' + (`rethinkdb -v`).gsub("\n", '') + ' (durability: soft)'
end
def title
'RethinkDB'
end
def setup
begin
r.db_create(@@DB_NAME).run(@conn)
r.db(@@DB_NAME).table_create('posts').run(@conn)
rescue
# I don't really care if these fail
end
end
def insert(attrs)
time = Time.now
attrs[:created_at] = time
attrs[:updated_at] = time
result = r.db(@@DB_NAME).table('posts').insert(attrs).run(@conn, durability: "soft")
result['generated_keys']
end
def read(id)
r.db(@@DB_NAME).table('posts').get(id).run(@conn)
end
def update(id, attrs)
time = Time.now
attrs[:updated_at] = time
result = r.db(@@DB_NAME).table('posts').get(id).update(attrs).run(@conn)
end
end