# HG changeset patch # User Kim Alvefur # Date 1422220640 -3600 # Node ID 6288591d5edfe25cf67dc4afb1b136363dead21d # Parent 620cc035ae1e414dea68389f34ca5e5d72d384e9 mod_storage_gdbm: Prepare for supporting multiple store types diff -r 620cc035ae1e -r 6288591d5edf mod_storage_gdbm/mod_storage_gdbm.lua --- 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