Mercurial > prosody-hg
comparison plugins/mod_storage_sql.lua @ 13967:758d5d4e83ca
mod_storage_sql: Switch mutating transactions to new API
This is just semantics at this point. A future commit will indicate
write transactions with BEGIN IMMEDIATE for SQLite3.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 19 Aug 2024 00:11:06 +0200 |
| parents | 9a69918b5e63 |
| children | 1b300c5a79d7 |
comparison
equal
deleted
inserted
replaced
| 13966:e7c52d0b0e0d | 13967:758d5d4e83ca |
|---|---|
| 159 return nil, result; | 159 return nil, result; |
| 160 end | 160 end |
| 161 return result; | 161 return result; |
| 162 end | 162 end |
| 163 function keyval_store:set(username, data) | 163 function keyval_store:set(username, data) |
| 164 return engine:transaction(keyval_store_set, data, username, self.store); | 164 return engine:write_transaction(keyval_store_set, data, username, self.store); |
| 165 end | 165 end |
| 166 function keyval_store:users() | 166 function keyval_store:users() |
| 167 local ok, result = engine:transaction(function() | 167 local ok, result = engine:transaction(function() |
| 168 local select_sql = [[ | 168 local select_sql = [[ |
| 169 SELECT DISTINCT "user" | 169 SELECT DISTINCT "user" |
| 217 function map_store:set(username, key, data) | 217 function map_store:set(username, key, data) |
| 218 if data == nil then data = self.remove; end | 218 if data == nil then data = self.remove; end |
| 219 return self:set_keys(username, { [key] = data }); | 219 return self:set_keys(username, { [key] = data }); |
| 220 end | 220 end |
| 221 function map_store:set_keys(username, keydatas) | 221 function map_store:set_keys(username, keydatas) |
| 222 local ok, result = engine:transaction(function() | 222 local ok, result = engine:write_transaction(function() |
| 223 local delete_sql = [[ | 223 local delete_sql = [[ |
| 224 DELETE FROM "prosody" | 224 DELETE FROM "prosody" |
| 225 WHERE "host"=? AND "user"=? AND "store"=? AND "key"=?; | 225 WHERE "host"=? AND "user"=? AND "store"=? AND "key"=?; |
| 226 ]]; | 226 ]]; |
| 227 local insert_sql = [[ | 227 local insert_sql = [[ |
| 301 | 301 |
| 302 function map_store:delete_all(key) | 302 function map_store:delete_all(key) |
| 303 if type(key) ~= "string" or key == "" then | 303 if type(key) ~= "string" or key == "" then |
| 304 return nil, "delete_all only supports non-empty string keys"; | 304 return nil, "delete_all only supports non-empty string keys"; |
| 305 end | 305 end |
| 306 local ok, result = engine:transaction(function() | 306 local ok, result = engine:write_transaction(function() |
| 307 local delete_sql = [[ | 307 local delete_sql = [[ |
| 308 DELETE FROM "prosody" | 308 DELETE FROM "prosody" |
| 309 WHERE "host"=? AND "store"=? AND "key"=?; | 309 WHERE "host"=? AND "store"=? AND "key"=?; |
| 310 ]]; | 310 ]]; |
| 311 engine:delete(delete_sql, host, self.store, key); | 311 engine:delete(delete_sql, host, self.store, key); |
| 331 local item_count = archive_item_count_cache:get(cache_key); | 331 local item_count = archive_item_count_cache:get(cache_key); |
| 332 | 332 |
| 333 if archive_item_limit then | 333 if archive_item_limit then |
| 334 if not item_count then | 334 if not item_count then |
| 335 item_count_cache_miss(); | 335 item_count_cache_miss(); |
| 336 local ok, ret = engine:transaction(function() | 336 local ok, ret = engine:write_transaction(function() |
| 337 local count_sql = [[ | 337 local count_sql = [[ |
| 338 SELECT COUNT(*) FROM "prosodyarchive" | 338 SELECT COUNT(*) FROM "prosodyarchive" |
| 339 WHERE "host"=? AND "user"=? AND "store"=?; | 339 WHERE "host"=? AND "user"=? AND "store"=?; |
| 340 ]]; | 340 ]]; |
| 341 local result = engine:select(count_sql, host, user, store); | 341 local result = engine:select(count_sql, host, user, store); |
| 365 if engine.params.driver ~= "SQLite3" then | 365 if engine.params.driver ~= "SQLite3" then |
| 366 -- SQLite3 doesn't enforce types :) | 366 -- SQLite3 doesn't enforce types :) |
| 367 when = math.floor(when); | 367 when = math.floor(when); |
| 368 end | 368 end |
| 369 with = with or ""; | 369 with = with or ""; |
| 370 local ok, ret = engine:transaction(function() | 370 local ok, ret = engine:write_transaction(function() |
| 371 local delete_sql = [[ | 371 local delete_sql = [[ |
| 372 DELETE FROM "prosodyarchive" | 372 DELETE FROM "prosodyarchive" |
| 373 WHERE "host"=? AND "user"=? AND "store"=? AND "key"=?; | 373 WHERE "host"=? AND "user"=? AND "store"=? AND "key"=?; |
| 374 ]]; | 374 ]]; |
| 375 local insert_sql = [[ | 375 local insert_sql = [[ |
| 540 return nil, "item-not-found"; | 540 return nil, "item-not-found"; |
| 541 end | 541 end |
| 542 | 542 |
| 543 function archive_store:set(username, key, new_value, new_when, new_with) | 543 function archive_store:set(username, key, new_value, new_when, new_with) |
| 544 local user,store = username,self.store; | 544 local user,store = username,self.store; |
| 545 local ok, result = engine:transaction(function () | 545 local ok, result = engine:write_transaction(function () |
| 546 | 546 |
| 547 local update_query = [[ | 547 local update_query = [[ |
| 548 UPDATE "prosodyarchive" | 548 UPDATE "prosodyarchive" |
| 549 SET %s | 549 SET %s |
| 550 WHERE %s | 550 WHERE %s |
| 619 end | 619 end |
| 620 | 620 |
| 621 function archive_store:delete(username, query) | 621 function archive_store:delete(username, query) |
| 622 query = query or {}; | 622 query = query or {}; |
| 623 local user,store = username,self.store; | 623 local user,store = username,self.store; |
| 624 local ok, stmt = engine:transaction(function() | 624 local ok, stmt = engine:write_transaction(function() |
| 625 local sql_query = "DELETE FROM \"prosodyarchive\" WHERE %s;"; | 625 local sql_query = "DELETE FROM \"prosodyarchive\" WHERE %s;"; |
| 626 local args = { host, user or "", store, }; | 626 local args = { host, user or "", store, }; |
| 627 local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", }; | 627 local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", }; |
| 628 if user == true then | 628 if user == true then |
| 629 table.remove(args, 2); | 629 table.remove(args, 2); |
| 749 if not ok then return ok, result end | 749 if not ok then return ok, result end |
| 750 return iterator(result); | 750 return iterator(result); |
| 751 end | 751 end |
| 752 | 752 |
| 753 function driver:purge(username) | 753 function driver:purge(username) |
| 754 return engine:transaction(function() | 754 return engine:write_transaction(function() |
| 755 engine:delete("DELETE FROM \"prosody\" WHERE \"host\"=? AND \"user\"=?", host, username); | 755 engine:delete("DELETE FROM \"prosody\" WHERE \"host\"=? AND \"user\"=?", host, username); |
| 756 engine:delete("DELETE FROM \"prosodyarchive\" WHERE \"host\"=? AND \"user\"=?", host, username); | 756 engine:delete("DELETE FROM \"prosodyarchive\" WHERE \"host\"=? AND \"user\"=?", host, username); |
| 757 end); | 757 end); |
| 758 end | 758 end |
| 759 | 759 |
