@@ -25,9 +25,9 @@ let create db =
2525 rc INTEGER NOT NULL ,
2626 parent TEXT ,
2727 FOREIGN KEY (parent) REFERENCES builds (id) ON DELETE RESTRICT
28- ) | } |> Db. or_fail ~cmd: " create builds" ;
28+ ) | } |> Db. or_fail db ~cmd: " create builds" ;
2929 Sqlite3. exec db {| CREATE INDEX IF NOT EXISTS lru
30- ON builds (rc, used) | } |> Db. or_fail ~cmd: " create lru index" ;
30+ ON builds (rc, used) | } |> Db. or_fail db ~cmd: " create lru index" ;
3131 let begin_transaction = Sqlite3. prepare db " BEGIN TRANSACTION" in
3232 let commit = Sqlite3. prepare db " COMMIT" in
3333 let rollback = Sqlite3. prepare db {| ROLLBACK | } in
@@ -44,30 +44,30 @@ let create db =
4444 { db; begin_transaction; commit; rollback; add; set_used; update_rc; exists; children; delete; lru; parent }
4545
4646let with_transaction t fn =
47- Db. exec t.begin_transaction [] ;
47+ Db. exec t.db t. begin_transaction [] ;
4848 match fn () with
49- | x -> Db. exec t.commit [] ; x
50- | exception ex -> Db. exec t.rollback [] ; raise ex
49+ | x -> Db. exec t.db t. commit [] ; x
50+ | exception ex -> Db. exec t.db t. rollback [] ; raise ex
5151
5252let add ?parent ~id ~now t =
5353 let now = format_timestamp now in
5454 match parent with
55- | None -> Db. exec t.add Sqlite3.Data. [ TEXT id; TEXT now; TEXT now; NULL ];
55+ | None -> Db. exec t.db t. add Sqlite3.Data. [ TEXT id; TEXT now; TEXT now; NULL ];
5656 | Some parent ->
5757 with_transaction t (fun () ->
58- Db. exec t.add Sqlite3.Data. [ TEXT id; TEXT now; TEXT now; TEXT parent ];
59- Db. exec t.update_rc Sqlite3.Data. [ INT 1L ; TEXT parent ];
58+ Db. exec t.db t. add Sqlite3.Data. [ TEXT id; TEXT now; TEXT now; TEXT parent ];
59+ Db. exec t.db t. update_rc Sqlite3.Data. [ INT 1L ; TEXT parent ];
6060 )
6161
6262let set_used ~id ~now t =
6363 let now = format_timestamp now in
64- Db. exec t.set_used Sqlite3.Data. [ TEXT now; TEXT id ]
64+ Db. exec t.db t. set_used Sqlite3.Data. [ TEXT now; TEXT id ]
6565
6666let children t id =
67- match Db. query_one t.exists Sqlite3.Data. [ TEXT id ] with
67+ match Db. query_one t.db t. exists Sqlite3.Data. [ TEXT id ] with
6868 | [ INT 0L ] -> Error `No_such_id
6969 | [ INT 1L ] ->
70- Db. query t.children Sqlite3.Data. [ TEXT id ] |> List. map (function
70+ Db. query t.db t. children Sqlite3.Data. [ TEXT id ] |> List. map (function
7171 | Sqlite3.Data. [ TEXT dep ] -> dep
7272 | x -> Fmt. failwith " Invalid row: %a" Db. dump_row x
7373 )
@@ -76,31 +76,31 @@ let children t id =
7676
7777let delete t id =
7878 with_transaction t (fun () ->
79- match Db. query_one t.parent Sqlite3.Data. [ TEXT id ] with
79+ match Db. query_one t.db t. parent Sqlite3.Data. [ TEXT id ] with
8080 | [ TEXT parent ] ->
81- Db. exec t.delete Sqlite3.Data. [ TEXT id ];
82- Db. exec t.update_rc Sqlite3.Data. [ INT (- 1L ); TEXT parent ]
81+ Db. exec t.db t. delete Sqlite3.Data. [ TEXT id ];
82+ Db. exec t.db t. update_rc Sqlite3.Data. [ INT (- 1L ); TEXT parent ]
8383 | [ NULL ] ->
84- Db. exec t.delete Sqlite3.Data. [ TEXT id ]
84+ Db. exec t.db t. delete Sqlite3.Data. [ TEXT id ]
8585 | x -> Fmt. failwith " Invalid row: %a" Db. dump_row x
8686 )
8787
8888let lru t ~before n =
89- Db. query t.lru Sqlite3.Data. [ TEXT (format_timestamp before); INT (Int64. of_int n) ]
89+ Db. query t.db t. lru Sqlite3.Data. [ TEXT (format_timestamp before); INT (Int64. of_int n) ]
9090 |> List. map @@ function
9191 | Sqlite3.Data. [ TEXT id ] -> id
9292 | x -> Fmt. failwith " Invalid row: %a" Db. dump_row x
9393
9494let close t =
95- Sqlite3. finalize t.begin_transaction |> Db. or_fail ~cmd: " finalize" ;
96- Sqlite3. finalize t.commit |> Db. or_fail ~cmd: " finalize" ;
97- Sqlite3. finalize t.rollback |> Db. or_fail ~cmd: " finalize" ;
98- Sqlite3. finalize t.add |> Db. or_fail ~cmd: " finalize" ;
99- Sqlite3. finalize t.set_used |> Db. or_fail ~cmd: " finalize" ;
100- Sqlite3. finalize t.update_rc |> Db. or_fail ~cmd: " finalize" ;
101- Sqlite3. finalize t.exists |> Db. or_fail ~cmd: " finalize" ;
102- Sqlite3. finalize t.children |> Db. or_fail ~cmd: " finalize" ;
103- Sqlite3. finalize t.delete |> Db. or_fail ~cmd: " finalize" ;
104- Sqlite3. finalize t.lru |> Db. or_fail ~cmd: " finalize" ;
105- Sqlite3. finalize t.parent |> Db. or_fail ~cmd: " finalize" ;
95+ Sqlite3. finalize t.begin_transaction |> Db. or_fail t.db ~cmd: " finalize" ;
96+ Sqlite3. finalize t.commit |> Db. or_fail t.db ~cmd: " finalize" ;
97+ Sqlite3. finalize t.rollback |> Db. or_fail t.db ~cmd: " finalize" ;
98+ Sqlite3. finalize t.add |> Db. or_fail t.db ~cmd: " finalize" ;
99+ Sqlite3. finalize t.set_used |> Db. or_fail t.db ~cmd: " finalize" ;
100+ Sqlite3. finalize t.update_rc |> Db. or_fail t.db ~cmd: " finalize" ;
101+ Sqlite3. finalize t.exists |> Db. or_fail t.db ~cmd: " finalize" ;
102+ Sqlite3. finalize t.children |> Db. or_fail t.db ~cmd: " finalize" ;
103+ Sqlite3. finalize t.delete |> Db. or_fail t.db ~cmd: " finalize" ;
104+ Sqlite3. finalize t.lru |> Db. or_fail t.db ~cmd: " finalize" ;
105+ Sqlite3. finalize t.parent |> Db. or_fail t.db ~cmd: " finalize" ;
106106 Db. close t.db
0 commit comments