equal
deleted
inserted
replaced
1 local next = next; |
1 local next = next; |
2 local setmetatable = setmetatable; |
2 local setmetatable = setmetatable; |
3 |
3 |
4 local log = require "util.logger".init("mongodb"); |
4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" ); |
5 local params = module:get_option("mongodb"); |
|
6 |
5 |
7 local mongo = require "mongo"; |
6 local mongo = require "mongo"; |
8 |
7 |
9 local conn = mongo.Connection.New ( true ); |
8 local conn = mongo.Connection.New ( true ); |
10 conn:connect ( params.server ); |
9 conn:connect ( params.server ); |
15 |
14 |
16 function keyval_store:get(username) |
15 function keyval_store:get(username) |
17 local host = module.host or "_global"; |
16 local host = module.host or "_global"; |
18 local store = self.store; |
17 local store = self.store; |
19 |
18 |
|
19 -- The database name can't have a period in it (hence it can't be a host/ip) |
20 local namespace = params.dbname .. "." .. host; |
20 local namespace = params.dbname .. "." .. host; |
21 local v = { _id = { store = store ; username = username } }; |
21 local v = { _id = { store = store ; username = username } }; |
22 |
22 |
23 local cursor , err = conn:query ( namespace , v ); |
23 local cursor , err = conn:query ( namespace , v ); |
24 if not cursor then return nil , err end; |
24 if not cursor then return nil , err end; |
30 |
30 |
31 function keyval_store:set(username, data) |
31 function keyval_store:set(username, data) |
32 local host = module.host or "_global"; |
32 local host = module.host or "_global"; |
33 local store = self.store; |
33 local store = self.store; |
34 |
34 |
|
35 -- The database name can't have a period in it (hence it can't be a host/ip) |
35 local namespace = params.dbname .. "." .. host; |
36 local namespace = params.dbname .. "." .. host; |
36 local v = { _id = { store = store ; username = username } }; |
37 local v = { _id = { store = store ; username = username } }; |
37 |
38 |
38 if next(data) ~= nil then -- set data |
39 if next(data) ~= nil then -- set data |
39 v.data = data; |
40 v.data = data; |