Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 9904:bf061f5512f7
mod_storage_sql: Implement archive summary API
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 25 Feb 2019 15:51:55 +0100 |
| parent | 9896:dafe1b544822 |
| child | 10002:b6b5b9d7417d |
comparison
equal
deleted
inserted
replaced
| 9903:2c5546cc5c70 | 9904:bf061f5512f7 |
|---|---|
| 415 local value, err = deserialize(row[2], row[3]); | 415 local value, err = deserialize(row[2], row[3]); |
| 416 assert(value ~= nil, err); | 416 assert(value ~= nil, err); |
| 417 return row[1], value, row[4], row[5]; | 417 return row[1], value, row[4], row[5]; |
| 418 end | 418 end |
| 419 end, total; | 419 end, total; |
| 420 end | |
| 421 | |
| 422 function archive_store:summary(username, query) | |
| 423 query = query or {}; | |
| 424 local user,store = username,self.store; | |
| 425 local ok, result = engine:transaction(function() | |
| 426 local sql_query = [[ | |
| 427 SELECT DISTINCT "with", COUNT(*) | |
| 428 FROM "prosodyarchive" | |
| 429 WHERE %s | |
| 430 GROUP BY "with" | |
| 431 ORDER BY "sort_id" %s%s; | |
| 432 ]]; | |
| 433 local args = { host, user or "", store, }; | |
| 434 local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", }; | |
| 435 | |
| 436 archive_where(query, args, where); | |
| 437 | |
| 438 archive_where_id_range(query, args, where); | |
| 439 | |
| 440 if query.limit then | |
| 441 args[#args+1] = query.limit; | |
| 442 end | |
| 443 | |
| 444 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse | |
| 445 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); | |
| 446 return engine:select(sql_query, unpack(args)); | |
| 447 end); | |
| 448 if not ok then return ok, result end | |
| 449 local summary = {}; | |
| 450 for row in result do | |
| 451 local with, count = row[1], row[2]; | |
| 452 summary[with] = count; | |
| 453 end | |
| 454 return summary; | |
| 420 end | 455 end |
| 421 | 456 |
| 422 function archive_store:delete(username, query) | 457 function archive_store:delete(username, query) |
| 423 query = query or {}; | 458 query = query or {}; |
| 424 local user,store = username,self.store; | 459 local user,store = username,self.store; |