# HG changeset patch # User Kim Alvefur # Date 1490974473 -7200 # Node ID 9545d0a9401fcf716a0ef8bb448a430a9cc873b4 # Parent ec7cab8e744d12c26f44609c70b22e8eda0e7650 mod_storage_internal: Separate driver from keyval implementation diff -r ec7cab8e744d -r 9545d0a9401f plugins/mod_storage_internal.lua --- a/plugins/mod_storage_internal.lua Fri Mar 31 17:29:08 2017 +0200 +++ b/plugins/mod_storage_internal.lua Fri Mar 31 17:34:33 2017 +0200 @@ -3,19 +3,23 @@ local host = module.host; local driver = {}; -local driver_mt = { __index = driver }; function driver:open(store, typ) - if typ and typ ~= "keyval" then + local mt = self[typ or "keyval"] + if not mt then return nil, "unsupported-store"; end - return setmetatable({ store = store, type = typ }, driver_mt); + return setmetatable({ store = store, type = typ }, mt); end -function driver:get(user) + +local keyval = { }; +driver.keyval = { __index = keyval }; + +function keyval:get(user) return datamanager.load(user, host, self.store); end -function driver:set(user, data) +function keyval:set(user, data) return datamanager.store(user, host, self.store, data); end @@ -23,7 +27,7 @@ return datamanager.stores(username, host); end -function driver:users() +function keyval:users() return datamanager.users(host, self.store, self.type); end