Software / code / prosody
Comparison
plugins/mod_storage_sql2.lua @ 6331:fc5113a4540e
plugins/mod_storage_sql2: Add map store support
| author | daurnimator <quae@daurnimator.com> |
|---|---|
| date | Thu, 07 Aug 2014 12:16:16 -0400 |
| parent | 6282:bce801e40484 |
| child | 6335:eaf6e7986934 |
comparison
equal
deleted
inserted
replaced
| 6330:a678d15e590e | 6331:fc5113a4540e |
|---|---|
| 214 end); | 214 end); |
| 215 if not ok then return ok, result end | 215 if not ok then return ok, result end |
| 216 return iterator(result); | 216 return iterator(result); |
| 217 end | 217 end |
| 218 | 218 |
| 219 local map_store = {}; | |
| 220 map_store.__index = map_store; | |
| 221 function map_store:get(username, key) | |
| 222 return engine:transaction(function() | |
| 223 if type(key) == "string" and key ~= "" then | |
| 224 local iter, state, first = engine:select("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", | |
| 225 host, username, self.store, key or ""); | |
| 226 local row = iter(state, first); | |
| 227 if row then | |
| 228 return deserialize(row.type, row.value); | |
| 229 else | |
| 230 return nil; | |
| 231 end | |
| 232 else | |
| 233 error("TODO: non-string keys"); | |
| 234 end | |
| 235 end); | |
| 236 end | |
| 237 function map_store:set(username, key, data) | |
| 238 return engine:transaction(function() | |
| 239 if data == nil then | |
| 240 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", | |
| 241 host, username, self.store, key or ""); | |
| 242 elseif type(key) == "string" and key ~= "" then | |
| 243 local t, value = assert(serialize(data)); | |
| 244 engine:update("UPDATE `prosody` SET `type`=?, `value`=? WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", | |
| 245 t, value, host, username, self.store, key); | |
| 246 else | |
| 247 error("TODO: non-string keys"); | |
| 248 end | |
| 249 return true; | |
| 250 end); | |
| 251 end | |
| 252 | |
| 219 local archive_store = {} | 253 local archive_store = {} |
| 220 archive_store.__index = archive_store | 254 archive_store.__index = archive_store |
| 221 function archive_store:append(username, key, when, with, value) | 255 function archive_store:append(username, key, when, with, value) |
| 222 if value == nil then -- COMPAT early versions | 256 if value == nil then -- COMPAT early versions |
| 223 when, with, value, key = key, when, with, value | 257 when, with, value, key = key, when, with, value |
| 339 end); | 373 end); |
| 340 end | 374 end |
| 341 | 375 |
| 342 local stores = { | 376 local stores = { |
| 343 keyval = keyval_store; | 377 keyval = keyval_store; |
| 378 map = map_store; | |
| 344 archive = archive_store; | 379 archive = archive_store; |
| 345 }; | 380 }; |
| 346 | 381 |
| 347 local driver = {}; | 382 local driver = {}; |
| 348 | 383 |