Comparison

plugins/mod_storage_sql.lua @ 6954:400badaf1fc7

mod_storage_sql: Add map store (backported from trunk)
author Matthew Wild <mwild1@gmail.com>
date Thu, 03 Dec 2015 15:03:24 +0000
parent 6953:b9276d677e76
child 7008:9beba2572e2b
comparison
equal deleted inserted replaced
6953:b9276d677e76 6954:400badaf1fc7
123 return iterator(result); 123 return iterator(result);
124 end 124 end
125 125
126 --- Archive store API 126 --- Archive store API
127 127
128 local map_store = {};
129 map_store.__index = map_store;
130 function map_store:get(username, key)
131 local ok, result = engine:transaction(function()
132 if type(key) == "string" and key ~= "" then
133 for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do
134 return deserialize(row[1], row[2]);
135 end
136 else
137 error("TODO: non-string keys");
138 end
139 end);
140 if not ok then return nil, result; end
141 return result;
142 end
143 function map_store:set(username, key, data)
144 local ok, result = engine:transaction(function()
145 if type(key) == "string" and key ~= "" then
146 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
147 host, username or "", self.store, key);
148 if data ~= nil then
149 local t, value = assert(serialize(data));
150 engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value);
151 end
152 else
153 error("TODO: non-string keys");
154 end
155 return true;
156 end);
157 if not ok then return nil, result; end
158 return result;
159 end
160
128 local archive_store = {} 161 local archive_store = {}
129 archive_store.caps = { 162 archive_store.caps = {
130 total = true; 163 total = true;
131 }; 164 };
132 archive_store.__index = archive_store 165 archive_store.__index = archive_store
251 end); 284 end);
252 end 285 end
253 286
254 local stores = { 287 local stores = {
255 keyval = keyval_store; 288 keyval = keyval_store;
289 map = map_store;
256 archive = archive_store; 290 archive = archive_store;
257 }; 291 };
258 292
259 --- Implement storage driver API 293 --- Implement storage driver API
260 294