Commit 135b0bfd567d18acbfeeca544093473765686e07

Authored by totoro
1 parent 23bb1d76

add function for deleting multiple records with a list of id on specified table_name

add function for getting a list of ids from where clause on specified table_name
Showing 1 changed file with 37 additions and 0 deletions   Show diff stats
controller/hk_sql_utils.anubis
... ... @@ -29,6 +29,23 @@ public define String
29 29 }
30 30 .
31 31  
  32 +public define Maybe(One)
  33 + delete_from_ids
  34 + (
  35 + SQLite3DataBase db,
  36 + String table_name,
  37 + List(Int) ids
  38 + )=
  39 + if sql_query_timeout(db,
  40 + "DELETE FROM "+table_name+
  41 + " WHERE id IN ("+join(", ", to_List_String(ids))+");",
  42 + [],
  43 + "delete_from_ids") is
  44 + {
  45 + error(_) then failure,
  46 + ok(_, _, _) then success(unique)
  47 + }.
  48 +
32 49 public define Int
33 50 get_count_by_clause
34 51 (
... ... @@ -56,3 +73,23 @@ public define Int
56 73 )=
57 74 get_count_by_clause(db, table_name, "")
58 75 .
  76 +
  77 +
  78 +public define List(Int)
  79 + get_ids_by_clause
  80 + (
  81 + SQLite3DataBase db,
  82 + String table_name,
  83 + String clause
  84 + )=
  85 + with final_clause = if clause = "" then
  86 + ""
  87 + else
  88 + "WHERE "+clause,
  89 +
  90 + if sql_query_timeout(db, "SELECT \"id\" FROM "+table_name+" "+final_clause+";", [], "get_ids_by_clause") is
  91 + {
  92 + error(_) then [],
  93 + ok(_, cursor, _) then db_get_integer_list(cursor)
  94 + }
  95 +.
... ...