Software /
code /
prosody-modules
Comparison
mod_storage_memory/mod_storage_memory.lua @ 1607:8b997d9cf09e
mod_storage_memory: Add support for map stores
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 12 Feb 2015 15:13:50 +0100 |
parent | 1259:fa7e402fcdc1 |
child | 1608:59fdf4f12343 |
comparison
equal
deleted
inserted
replaced
1606:2c8b985ebde5 | 1607:8b997d9cf09e |
---|---|
17 function keyval_store:set(username, data) | 17 function keyval_store:set(username, data) |
18 self.store[username] = data; | 18 self.store[username] = data; |
19 return true; | 19 return true; |
20 end | 20 end |
21 | 21 |
22 local map_store = {}; | |
23 map_store.__index = map_store; | |
24 | |
25 function map_store:get(username, key) | |
26 local userstore = self.store[username]; | |
27 if type(userstore) == "table" then | |
28 return userstore[key]; | |
29 end | |
30 end | |
31 | |
32 function map_store:set(username, key, data) | |
33 local userstore = self.store[username]; | |
34 if userstore == nil then | |
35 userstore = {}; | |
36 self.store[username] = userstore; | |
37 end | |
38 userstore[key] = data; | |
39 return true; | |
40 end | |
41 | |
22 local stores = { | 42 local stores = { |
23 keyval = keyval_store; | 43 keyval = keyval_store; |
44 map = map_store; | |
24 } | 45 } |
25 | 46 |
26 local driver = {}; | 47 local driver = {}; |
27 | 48 |
28 function driver:open(store, typ) | 49 function driver:open(store, typ) |