Comparison

mod_storage_mongodb/mod_storage_mongodb.lua @ 506:0e07810550c8

mod_storage_mongodb: Use _global as host when none provided
author James Callahan <james@chatid.com>
date Tue, 13 Dec 2011 12:30:01 +1100
parent 505:b6d2ac386120
child 507:46f578da4ff0
comparison
equal deleted inserted replaced
505:b6d2ac386120 506:0e07810550c8
12 12
13 local keyval_store = {}; 13 local keyval_store = {};
14 keyval_store.__index = keyval_store; 14 keyval_store.__index = keyval_store;
15 15
16 function keyval_store:get(username) 16 function keyval_store:get(username)
17 local host, store = module.host, self.store; 17 local host = module.host or "_global";
18 local store = self.store;
18 19
19 local namespace = params.dbname .. "." .. host; 20 local namespace = params.dbname .. "." .. host;
20 local v = { _id = { store = store ; username = username } }; 21 local v = { _id = { store = store ; username = username } };
21 22
22 local cursor , err = conn:query ( namespace , v ); 23 local cursor , err = conn:query ( namespace , v );
26 if not r then return nil , err end; 27 if not r then return nil , err end;
27 return r.data; 28 return r.data;
28 end 29 end
29 30
30 function keyval_store:set(username, data) 31 function keyval_store:set(username, data)
31 local host, store = module.host, self.store; 32 local host = module.host or "_global";
32 if not host then return nil , "mongodb cannot currently be used for host-less data" end; 33 local store = self.store;
33 34
34 local namespace = params.dbname .. "." .. host; 35 local namespace = params.dbname .. "." .. host;
35 local v = { _id = { store = store ; username = username } }; 36 local v = { _id = { store = store ; username = username } };
36 37
37 if next(data) ~= nil then -- set data 38 if next(data) ~= nil then -- set data