Comparison

mod_storage_mongodb/mod_storage_mongodb.lua @ 1010:fd420237a5e4

mod_storage_mongodb: Use util.json to encode our data (handles non-string table keys, etc).
author Waqas Hussain <waqas20@gmail.com>
date Thu, 09 May 2013 11:23:07 -0400
parent 813:2469f779b3f7
child 1324:853a382c9bd6
comparison
equal deleted inserted replaced
1009:fcba646eb20a 1010:fd420237a5e4
4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" ); 4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" );
5 5
6 prosody.unlock_globals(); 6 prosody.unlock_globals();
7 local mongo = require "mongo"; 7 local mongo = require "mongo";
8 prosody.lock_globals(); 8 prosody.lock_globals();
9
10 local json = require "util.json";
9 11
10 local conn 12 local conn
11 13
12 local keyval_store = {}; 14 local keyval_store = {};
13 keyval_store.__index = keyval_store; 15 keyval_store.__index = keyval_store;
36 local namespace = params.dbname .. "." .. host; 38 local namespace = params.dbname .. "." .. host;
37 local v = { _id = { store = store ; username = username } }; 39 local v = { _id = { store = store ; username = username } };
38 40
39 if next(data) ~= nil then -- set data 41 if next(data) ~= nil then -- set data
40 v.data = data; 42 v.data = data;
41 return conn:insert ( namespace , v ); 43 return conn:insert ( namespace , json.encode(v) );
42 else -- delete data 44 else -- delete data
43 return conn:remove ( namespace , v ); 45 return conn:remove ( namespace , v );
44 end; 46 end;
45 end 47 end
46 48