Comparison

plugins/mod_storage_sql.lua @ 8395:fbb9a1c2120e

mod_storage_sql: Add support for truncating deletion
author Kim Alvefur <zash@zash.se>
date Thu, 09 Nov 2017 16:50:36 +0100
parent 8294:90576b60f2d0
child 8410:54ff1f91e4db
comparison
equal deleted inserted replaced
8394:4892c22403d5 8395:fbb9a1c2120e
372 table.remove(args, 2); 372 table.remove(args, 2);
373 table.remove(where, 2); 373 table.remove(where, 2);
374 end 374 end
375 archive_where(query, args, where); 375 archive_where(query, args, where);
376 archive_where_id_range(query, args, where); 376 archive_where_id_range(query, args, where);
377 sql_query = sql_query:format(t_concat(where, " AND ")); 377 if query.truncate == nil then
378 sql_query = sql_query:format(t_concat(where, " AND "));
379 else
380 args[#args+1] = query.truncate;
381 local unlimited = "ALL";
382 if engine.params.driver == "SQLite3" then
383 sql_query = [[
384 DELETE FROM "prosodyarchive"
385 WHERE %s
386 ORDER BY "sort_id" %s
387 LIMIT %s OFFSET ?;
388 ]];
389 unlimited = "-1";
390 else
391 sql_query = [[
392 DELETE FROM "prosodyarchive"
393 WHERE "sort_id" IN (
394 SELECT "sort_id" FROM "prosodyarchive"
395 WHERE %s
396 ORDER BY "sort_id" %s
397 LIMIT %s OFFSET ?
398 );]];
399 if engine.params.driver == "MySQL" then
400 unlimited = "18446744073709551615";
401 end
402 end
403 sql_query = string.format(sql_query, t_concat(where, " AND "),
404 query.reverse and "ASC" or "DESC", unlimited);
405 end
378 return engine:delete(sql_query, unpack(args)); 406 return engine:delete(sql_query, unpack(args));
379 end); 407 end);
380 return ok and stmt:affected(), stmt; 408 return ok and stmt:affected(), stmt;
381 end 409 end
382 410