A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals
Revisión | 663aca5da36673c2239917dcdbef58263cd666d1 (tree) |
---|---|
Tiempo | 2023-06-05 06:31:45 |
Autor | Corbin <cds@corb...> |
Commiter | Corbin |
Add convenience functions for SQL SELECT statements.
@@ -32,6 +32,22 @@ let check_select stmt vals f = | ||
32 | 32 | Rc.check (bind_values stmt vals); |
33 | 33 | Rc.check (iter stmt ~f) |
34 | 34 | |
35 | +let check_fold stmt vals f init = | |
36 | + Rc.check (bind_values stmt vals); | |
37 | + let rc, acc = fold stmt ~f ~init in | |
38 | + Rc.check rc; | |
39 | + acc | |
40 | + | |
41 | +let check_one_row stmt vals g = | |
42 | + Rc.check (bind_values stmt vals); | |
43 | + let rc, acc = | |
44 | + fold stmt | |
45 | + ~f:(fun acc row -> match acc with None -> Some (g row) | o -> o) | |
46 | + ~init:None | |
47 | + in | |
48 | + Rc.check rc; | |
49 | + acc | |
50 | + | |
35 | 51 | let with_db db_path f = |
36 | 52 | let db = create db_path in |
37 | 53 | f db; |
@@ -7,4 +7,17 @@ val check_insert : Sqlite3.stmt -> Sqlite3.Data.t list -> unit | ||
7 | 7 | val check_select : |
8 | 8 | Sqlite3.stmt -> Sqlite3.Data.t list -> (Sqlite3.Data.t array -> unit) -> unit |
9 | 9 | |
10 | +val check_fold : | |
11 | + Sqlite3.stmt -> | |
12 | + Sqlite3.Data.t list -> | |
13 | + ('a -> Sqlite3.Data.t array -> 'a) -> | |
14 | + 'a -> | |
15 | + 'a | |
16 | + | |
17 | +val check_one_row : | |
18 | + Sqlite3.stmt -> | |
19 | + Sqlite3.Data.t list -> | |
20 | + (Sqlite3.Data.t array -> 'a) -> | |
21 | + 'a option | |
22 | + | |
10 | 23 | val with_db : string -> (t -> unit) -> unit |