Comparison

plugins/mod_storage_internal.lua @ 8018:9545d0a9401f

mod_storage_internal: Separate driver from keyval implementation
author Kim Alvefur <zash@zash.se>
date Fri, 31 Mar 2017 17:34:33 +0200
parent 6283:7cf6d3a2c855
child 8019:925098aad268
comparison
equal deleted inserted replaced
8017:ec7cab8e744d 8018:9545d0a9401f
1 local datamanager = require "core.storagemanager".olddm; 1 local datamanager = require "core.storagemanager".olddm;
2 2
3 local host = module.host; 3 local host = module.host;
4 4
5 local driver = {}; 5 local driver = {};
6 local driver_mt = { __index = driver };
7 6
8 function driver:open(store, typ) 7 function driver:open(store, typ)
9 if typ and typ ~= "keyval" then 8 local mt = self[typ or "keyval"]
9 if not mt then
10 return nil, "unsupported-store"; 10 return nil, "unsupported-store";
11 end 11 end
12 return setmetatable({ store = store, type = typ }, driver_mt); 12 return setmetatable({ store = store, type = typ }, mt);
13 end 13 end
14 function driver:get(user) 14
15 local keyval = { };
16 driver.keyval = { __index = keyval };
17
18 function keyval:get(user)
15 return datamanager.load(user, host, self.store); 19 return datamanager.load(user, host, self.store);
16 end 20 end
17 21
18 function driver:set(user, data) 22 function keyval:set(user, data)
19 return datamanager.store(user, host, self.store, data); 23 return datamanager.store(user, host, self.store, data);
20 end 24 end
21 25
22 function driver:stores(username) 26 function driver:stores(username)
23 return datamanager.stores(username, host); 27 return datamanager.stores(username, host);
24 end 28 end
25 29
26 function driver:users() 30 function keyval:users()
27 return datamanager.users(host, self.store, self.type); 31 return datamanager.users(host, self.store, self.type);
28 end 32 end
29 33
30 function driver:purge(user) 34 function driver:purge(user)
31 return datamanager.purge(user, host); 35 return datamanager.purge(user, host);