• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals


Commit MetaInfo

Revisión663aca5da36673c2239917dcdbef58263cd666d1 (tree)
Tiempo2023-06-05 06:31:45
AutorCorbin <cds@corb...>
CommiterCorbin

Log Message

Add convenience functions for SQL SELECT statements.

Cambiar Resumen

Diferencia incremental

--- a/src/storage.ml
+++ b/src/storage.ml
@@ -32,6 +32,22 @@ let check_select stmt vals f =
3232 Rc.check (bind_values stmt vals);
3333 Rc.check (iter stmt ~f)
3434
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+
3551 let with_db db_path f =
3652 let db = create db_path in
3753 f db;
--- a/src/storage.mli
+++ b/src/storage.mli
@@ -7,4 +7,17 @@ val check_insert : Sqlite3.stmt -> Sqlite3.Data.t list -> unit
77 val check_select :
88 Sqlite3.stmt -> Sqlite3.Data.t list -> (Sqlite3.Data.t array -> unit) -> unit
99
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+
1023 val with_db : string -> (t -> unit) -> unit