Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 6955:c9cbe3cbe498
Merge 0.10->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 03 Dec 2015 15:43:02 +0000 |
parent | 6954:400badaf1fc7 |
child | 7008:9beba2572e2b |
comparison
equal
deleted
inserted
replaced
6952:db085e55555f | 6955:c9cbe3cbe498 |
---|---|
105 local ok, result = engine:transaction(keyval_store_get); | 105 local ok, result = engine:transaction(keyval_store_get); |
106 if not ok then | 106 if not ok then |
107 module:log("error", "Unable to read from database %s store for %s: %s", store, username or "<host>", result); | 107 module:log("error", "Unable to read from database %s store for %s: %s", store, username or "<host>", result); |
108 return nil, result; | 108 return nil, result; |
109 end | 109 end |
110 return result; | 110 return result; |
111 end | 111 end |
112 function keyval_store:set(username, data) | 112 function keyval_store:set(username, data) |
113 user,store = username,self.store; | 113 user,store = username,self.store; |
114 return engine:transaction(function() | 114 return engine:transaction(function() |
115 return keyval_store_set(data); | 115 return keyval_store_set(data); |
122 if not ok then return ok, result end | 122 if not ok then return ok, result end |
123 return iterator(result); | 123 return iterator(result); |
124 end | 124 end |
125 | 125 |
126 --- Archive store API | 126 --- Archive store API |
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 | |
127 | 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 }; |
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 |