4 module G
= Demo_caml_gen.Sqlgg
(Sqlgg_sqlite3
)
6 let explain msg db
= printf
"%s : %s\n" msg
(errmsg db
)
9 let db = db_open
":memory:" in
15 (* add all person records *)
16 G.add_person
db "John" "Black";
17 let john = last_insert_rowid
db in
18 G.add_person
db "Ivan" "Petrov";
19 let ivan = last_insert_rowid
db in
20 G.add_person
db "Sancho" "Alvares";
21 let sancho = last_insert_rowid
db in
23 (* add money relations *)
24 G.add_money
db john ivan 200L;
25 G.add_money
db ~src
:john ~dst
:sancho ~amount
:100L;
26 G.add_money
db ~amount
:250L ~dst
:sancho ~src
:john;
27 G.add_money
db sancho ivan 300L;
29 (* summarize by person and output *)
30 print_endline
"Total transfers:";
31 G.calc_total
db (printf
"%s = %Lu\n");
32 printf
"Total total: %Lu\n" (G.Fold.calc_total
db (fun _
-> Int64.add
) 0L);
35 print_endline
"Donors:";
36 G.list_donors
db "petrov" 100L print_endline
;
38 (* properly close database *)
43 let _ = Printexc.print
main ()