Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 13151:7ebb3d6afcd1
mod_storage_sql: Add some TODO comments for future UPSERT work
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 11 Jun 2023 20:25:50 +0200 |
| parent | 13150:9e6ede86d35d |
| child | 13154:6cf5c215825d |
comparison
equal
deleted
inserted
replaced
| 13150:9e6ede86d35d | 13151:7ebb3d6afcd1 |
|---|---|
| 215 FROM "prosody" | 215 FROM "prosody" |
| 216 WHERE "host"=? AND "user"=? AND "store"=? AND "key"=? | 216 WHERE "host"=? AND "user"=? AND "store"=? AND "key"=? |
| 217 LIMIT 1; | 217 LIMIT 1; |
| 218 ]]; | 218 ]]; |
| 219 for key, data in pairs(keydatas) do | 219 for key, data in pairs(keydatas) do |
| 220 -- TODO Test UPSERT in PostgreSQL before enabling it. | |
| 220 if type(key) == "string" and key ~= "" and engine.params.driver == "SQLite3" and data ~= self.remove then | 221 if type(key) == "string" and key ~= "" and engine.params.driver == "SQLite3" and data ~= self.remove then |
| 221 local t, value = assert(serialize(data)); | 222 local t, value = assert(serialize(data)); |
| 222 engine:insert(upsert_sql, host, username or "", self.store, key, t, value, t, value); | 223 engine:insert(upsert_sql, host, username or "", self.store, key, t, value, t, value); |
| 223 elseif type(key) == "string" and key ~= "" then | 224 elseif type(key) == "string" and key ~= "" then |
| 224 engine:delete(delete_sql, | 225 engine:delete(delete_sql, |
| 346 INSERT INTO "prosodyarchive" | 347 INSERT INTO "prosodyarchive" |
| 347 ("host", "user", "store", "when", "with", "key", "type", "value") | 348 ("host", "user", "store", "when", "with", "key", "type", "value") |
| 348 VALUES (?,?,?,?,?,?,?,?); | 349 VALUES (?,?,?,?,?,?,?,?); |
| 349 ]]; | 350 ]]; |
| 350 if key then | 351 if key then |
| 352 -- TODO use UPSERT like map store | |
| 351 local result = engine:delete(delete_sql, host, user or "", store, key); | 353 local result = engine:delete(delete_sql, host, user or "", store, key); |
| 352 if result and item_count then | 354 if result and item_count then |
| 353 item_count = item_count - result:affected(); | 355 item_count = item_count - result:affected(); |
| 354 end | 356 end |
| 355 else | 357 else |