Class: Omnidata::Adapters::MongodbAdapter
Instance Attribute Summary
#config, #name
Instance Method Summary
collapse
#initialize
Instance Method Details
#count(table_name) ⇒ Object
32
33
34
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 32
def count(table_name)
table(table_name).count
end
|
#create(table_name, attrs) ⇒ Object
23
24
25
26
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 23
def create(table_name, attrs)
key = table(table_name).insert(attrs)
key.to_s
end
|
#database ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 7
def database
@db ||= begin
host = config[:host]
port = config[:port]
Mongo::Connection.new(host, port).db(config[:database])
end
end
|
#destroy(pk, table_name) ⇒ Object
36
37
38
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 36
def destroy(pk, table_name)
table(table_name).remove("_id" => build_key(pk))
end
|
#find(pk, table_name) ⇒ Object
15
16
17
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 15
def find(pk, table_name)
find_one(pk, table_name)
end
|
#find_one(pk, table_name) ⇒ Object
19
20
21
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 19
def find_one(pk, table_name)
table(table_name).find_one("_id" => build_key(pk))
end
|
#update(pk, table_name, attrs) ⇒ Object
28
29
30
|
# File 'lib/omnidata/adapters/mongodb_adapter.rb', line 28
def update(pk, table_name, attrs)
table(table_name).update({"_id" => pk}, {"$set" => attrs})
end
|