plugins/mod_storage_sql.lua
changeset 10225 068692cb9e78
parent 10224 1e2b444acb72
child 10226 51f145094648
equal deleted inserted replaced
10224:1e2b444acb72 10225:068692cb9e78
   422 function archive_store:summary(username, query)
   422 function archive_store:summary(username, query)
   423 	query = query or {};
   423 	query = query or {};
   424 	local user,store = username,self.store;
   424 	local user,store = username,self.store;
   425 	local ok, result = engine:transaction(function()
   425 	local ok, result = engine:transaction(function()
   426 		local sql_query = [[
   426 		local sql_query = [[
   427 		SELECT DISTINCT "with", COUNT(*)
   427 		SELECT DISTINCT "with", COUNT(*), MAX("when")
   428 		FROM "prosodyarchive"
   428 		FROM "prosodyarchive"
   429 		WHERE %s
   429 		WHERE %s
   430 		GROUP BY "with"
   430 		GROUP BY "with"
   431 		ORDER BY "sort_id" %s%s;
   431 		ORDER BY "sort_id" %s%s;
   432 		]];
   432 		]];
   445 			and "DESC" or "ASC", query.limit and " LIMIT ?" or "");
   445 			and "DESC" or "ASC", query.limit and " LIMIT ?" or "");
   446 		return engine:select(sql_query, unpack(args));
   446 		return engine:select(sql_query, unpack(args));
   447 	end);
   447 	end);
   448 	if not ok then return ok, result end
   448 	if not ok then return ok, result end
   449 	local counts = {};
   449 	local counts = {};
       
   450 	local latest = {};
   450 	for row in result do
   451 	for row in result do
   451 		local with, count = row[1], row[2];
   452 		local with, count = row[1], row[2];
   452 		counts[with] = count;
   453 		counts[with] = count;
       
   454 		latest[with] = row[3];
   453 	end
   455 	end
   454 	return {
   456 	return {
   455 		counts = counts;
   457 		counts = counts;
       
   458 		latest = latest;
   456 	};
   459 	};
   457 end
   460 end
   458 
   461 
   459 function archive_store:delete(username, query)
   462 function archive_store:delete(username, query)
   460 	query = query or {};
   463 	query = query or {};