class Omnidata::Adapters::MongodbAdapter
Public Instance Methods
count(table_name)
click to toggle source
# File lib/omnidata/adapters/mongodb_adapter.rb, line 32 def count(table_name) table(table_name).count end
create(table_name, attrs)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/omnidata/adapters/mongodb_adapter.rb, line 28 def update(pk, table_name, attrs) table(table_name).update({"_id" => pk}, {"$set" => attrs}) end
Private Instance Methods
build_key(pk)
click to toggle source
# File lib/omnidata/adapters/mongodb_adapter.rb, line 41 def build_key(pk) pk.kind_of?(String) ? BSON::ObjectId(pk) : pk end
table(name)
click to toggle source
# File lib/omnidata/adapters/mongodb_adapter.rb, line 45 def table(name) database.collection(name) end