comparison plugins/mod_storage_sql2.lua @ 6609:d2faaaca695d

Merge 0.10->trunk
author Matthew Wild <mwild1@gmail.com>
date Fri, 27 Mar 2015 22:24:57 +0000
parents b89406fa076c
children eb9c842b80fa
comparison
equal deleted inserted replaced
6608:b6e558febb7a 6609:d2faaaca695d
212 end); 212 end);
213 if not ok then return ok, result end 213 if not ok then return ok, result end
214 return iterator(result); 214 return iterator(result);
215 end 215 end
216 216
217 local map_store = {};
218 map_store.__index = map_store;
219 function map_store:get(username, key)
220 local ok, result = engine:transaction(function()
221 if type(key) == "string" and key ~= "" then
222 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do
223 return deserialize(row[1], row[2]);
224 end
225 else
226 error("TODO: non-string keys");
227 end
228 end);
229 if not ok then return nil, result; end
230 return result;
231 end
232 function map_store:set(username, key, data)
233 local ok, result = engine:transaction(function()
234 if type(key) == "string" and key ~= "" then
235 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
236 host, username or "", self.store, key);
237 if data ~= nil then
238 local t, value = assert(serialize(data));
239 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value);
240 end
241 else
242 error("TODO: non-string keys");
243 end
244 return true;
245 end);
246 if not ok then return nil, result; end
247 return result;
248 end
249
217 local archive_store = {} 250 local archive_store = {}
218 archive_store.__index = archive_store 251 archive_store.__index = archive_store
219 function archive_store:append(username, key, when, with, value) 252 function archive_store:append(username, key, when, with, value)
220 if value == nil then -- COMPAT early versions 253 if value == nil then -- COMPAT early versions
221 when, with, value, key = key, when, with, value 254 when, with, value, key = key, when, with, value
337 end); 370 end);
338 end 371 end
339 372
340 local stores = { 373 local stores = {
341 keyval = keyval_store; 374 keyval = keyval_store;
375 map = map_store;
342 archive = archive_store; 376 archive = archive_store;
343 }; 377 };
344 378
345 local driver = {}; 379 local driver = {};
346 380