Mercurial > prosody-modules
changeset 1595:6288591d5edf
mod_storage_gdbm: Prepare for supporting multiple store types
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 25 Jan 2015 22:17:20 +0100 (2015-01-25) |
parents | 620cc035ae1e |
children | b362e6c00fd1 |
files | mod_storage_gdbm/mod_storage_gdbm.lua |
diffstat | 1 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_storage_gdbm/mod_storage_gdbm.lua Sun Jan 25 19:52:39 2015 +0100 +++ b/mod_storage_gdbm/mod_storage_gdbm.lua Sun Jan 25 22:17:20 2015 +0100 @@ -18,28 +18,33 @@ local cache = {}; -local driver = {}; -local driver_mt = { __index = driver }; +local keyval = {}; +local keyval_mt = { __index = keyval, suffix = ".db" }; -function driver:set(user, value) +function keyval:set(user, value) local ok, err = gdbm.replace(self._db, user or "@", serialize(value)); if not ok then return nil, err; end return true; end -function driver:get(user) +function keyval:get(user) local data, err = gdbm.fetch(self._db, user or "@"); if not data then return nil, err; end return deserialize(data); end +local drivers = { + keyval = keyval_mt; +} + function open(_, store, typ) typ = typ or "keyval"; - if typ ~= "keyval" then + local driver_mt = drivers[typ]; + if not driver_mt then return nil, "unsupported-store"; end - local db_path = path.join(base_path, store) .. ".db"; + local db_path = path.join(base_path, store) .. driver_mt.suffix; local db = cache[db_path]; if not db then