···11+open Util.Rapper
12open Util.Syntax
22-include Caqti_type.Std
33-include Caqti_request.Infix
44-include Lwt_result.Syntax
53module Block_map = Mist.Storage.Block_map
66-77-module Cid : Rapper.CUSTOM with type t = Cid.t = struct
88- type t = Cid.t
99-1010- let t =
1111- let encode cid =
1212- try Ok (Cid.to_string cid) with e -> Error (Printexc.to_string e)
1313- in
1414- Caqti_type.(custom ~encode ~decode:Cid.of_string string)
1515-end
1616-1717-module Blob : Rapper.CUSTOM with type t = bytes = struct
1818- type t = bytes
1919-2020- let t =
2121- let encode blob =
2222- try Ok (Bytes.to_string blob) with e -> Error (Printexc.to_string e)
2323- in
2424- let decode blob =
2525- try Ok (Bytes.of_string blob) with e -> Error (Printexc.to_string e)
2626- in
2727- Caqti_type.(custom ~encode ~decode string)
2828-end
294305type t = {connection: Caqti_lwt.connection}
316···11792 in
11893 aux (Ok 0) queries
119949595+let connect db_uri =
9696+ let%lwt connection = Util.connect_sqlite db_uri in
9797+ let$! () = Queries.create_table connection in
9898+ Lwt.return {connection}
9999+120100let get_bytes t cid =
121101 let$! b_opt = Queries.get_block cid t.connection in
122102 match b_opt with
···163143let delete_many t cids =
164144 let$! deleted = Queries.delete_blocks cids t.connection in
165145 Lwt.return_ok (List.length deleted)
166166-167167-let connect db_uri =
168168- let%lwt connection = Util.connect_sqlite db_uri in
169169- let$! () = Queries.create_table connection in
170170- Lwt.return {connection}
+25
pegasus/lib/util.ml
···33 match%lwt m with Ok x -> f x | Error e -> raise (Caqti_error.Exn e)
44end
5566+module Rapper = struct
77+ module Cid : Rapper.CUSTOM with type t = Cid.t = struct
88+ type t = Cid.t
99+1010+ let t =
1111+ let encode cid =
1212+ try Ok (Cid.to_string cid) with e -> Error (Printexc.to_string e)
1313+ in
1414+ Caqti_type.(custom ~encode ~decode:Cid.of_string string)
1515+ end
1616+1717+ module Blob : Rapper.CUSTOM with type t = bytes = struct
1818+ type t = bytes
1919+2020+ let t =
2121+ let encode blob =
2222+ try Ok (Bytes.to_string blob) with e -> Error (Printexc.to_string e)
2323+ in
2424+ let decode blob =
2525+ try Ok (Bytes.of_string blob) with e -> Error (Printexc.to_string e)
2626+ in
2727+ Caqti_type.(custom ~encode ~decode string)
2828+ end
2929+end
3030+631let connect_sqlite db_uri =
732 let open Syntax in
833 match%lwt Caqti_lwt.connect (Uri.of_string db_uri) with