Skip to content

Commit cee1168

Browse files
author
Cuihtlauac ALVARADO
committed
Display online doc url
1 parent 9cef608 commit cee1168

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ C functions name prefixes are turned into modules. C functions name with suffix
1010
* `mongoc_database_get_collection_names_with_opts` is exposed as `Mongoc.Database.get_collection_names`
1111

1212
The library `libbson` is exposed as a submodule `Mongoc.Bson`.
13+
14+
Online documentation: https://tarides.github.io/mongoc-ocaml/mongoc/

lib/bson/bson.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ end
3232
let some = Ctypes.allocate t
3333
let none = Ctypes.(from_voidp t null)
3434

35+
let ptr_of_opt = Option.value ~default:none
36+
3537
let get_version () =
3638
() |> C.Functions.get_version |> Ctypes_std_views.string_of_char_ptr
3739

@@ -73,5 +75,4 @@ let as_relaxed_extended_json ?length (bson : t) =
7375
(* TODO: C.Functions.free (to_voidp str) *)
7476

7577
let as_json = as_relaxed_extended_json
76-
77-
let destroy (bson : t_struct ptr) = C.Functions.destroy bson |> ignore
78+
let destroy (bson : t) = C.Functions.destroy bson |> ignore

lib/bson/bson.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818

1919
val some : t_struct -> t
2020
val none : t
21+
val ptr_of_opt : t opt
2122
val t : t_struct Ctypes_static.typ
2223
val get_version : unit -> string
2324
val get_major_version : unit -> int

lib/bson/type_description.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module Types (F : Ctypes.TYPE) = struct
2-
open Ctypes_static
32
open F
43

54
module Error = struct
65
type t
76

8-
let t : t structure typ = typedef (structure "bson_error_t") "bson_error_t"
7+
let t : t Ctypes_static.structure typ =
8+
typedef (structure "bson_error_t") "bson_error_t"
9+
910
let domain = field t "domain" uint32_t
1011
let code = field t "code" uint32_t
1112
let message = field t "message" (array 504 char)
@@ -14,6 +15,6 @@ module Types (F : Ctypes.TYPE) = struct
1415

1516
type t
1617

17-
let t : t structure typ = typedef (structure "bson_t") "bson_t"
18+
let t : t Ctypes_static.structure typ = typedef (structure "bson_t") "bson_t"
1819
let () = seal t
1920
end

lib/mongoc.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ end = struct
100100
let find ?(opts : Bson.t option) ?(read_prefs : Read_prefs.t option)
101101
(coll : t) (filter : Bson.t) : Cursor.t =
102102
let opts = Option.value ~default:Bson.none opts in
103-
let read_prefs = Option.value read_prefs ~default:Read_prefs.none in
103+
let read_prefs = Option.value ~default:Read_prefs.none read_prefs in
104104
C.Functions.Collection.find_with_opts coll filter opts read_prefs
105105

106106
let count_documents ?(opts : Bson.t option)
107107
?(read_prefs : Read_prefs.t option) (coll : t) (filter : Bson.t) :
108108
(Int64.t, Bson.Error.t) result =
109109
let opts = Option.value ~default:Bson.none opts in
110-
let read_prefs = Option.value read_prefs ~default:Read_prefs.none in
110+
let read_prefs = Option.value ~default:Read_prefs.none read_prefs in
111111
let error = Ctypes.(make Bson.Error.t |> addr) in
112112
let count =
113113
C.Functions.Collection.count_documents coll filter opts read_prefs
@@ -119,11 +119,9 @@ end = struct
119119
(Bson.t, Bson.Error.t) result =
120120
let error = Ctypes.(make Bson.Error.t |> addr) in
121121
let opts = Option.value ~default:Bson.none opts in
122-
let reply = Ctypes.make Bson.t in
123-
if
124-
C.Functions.Collection.insert_one coll document opts (Ctypes.addr reply)
125-
error
126-
then Ok (Ctypes.addr reply)
122+
let reply = Ctypes.(make Bson.t |> addr) in
123+
if C.Functions.Collection.insert_one coll document opts reply error then
124+
Ok reply
127125
else Error error
128126

129127
let drop (coll : t) =

lib/type_description.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
module Types (F : Ctypes.TYPE) = struct
2-
open Ctypes_static
32
open F
43

54
module Error = struct
65
type t
76

8-
let t : t structure typ = typedef (structure "bson_error_t") "bson_error_t"
7+
let t : t Ctypes_static.structure typ =
8+
typedef (structure "bson_error_t") "bson_error_t"
9+
910
let () = seal t
1011
end
1112

1213
module Read_prefs = struct
1314
type t
1415

15-
let t : t structure typ =
16+
let t : t Ctypes_static.structure typ =
1617
typedef (structure "_mongoc_read_prefs_t") "mongoc_read_prefs_t"
1718
end
1819

1920
module Uri = struct
2021
type t
2122

22-
let t : t structure typ = typedef (structure "_mongoc_uri_t") "mongoc_uri_t"
23+
let t : t Ctypes_static.structure typ =
24+
typedef (structure "_mongoc_uri_t") "mongoc_uri_t"
2325
end
2426

2527
module Database = struct
2628
type t
2729

28-
let t : t structure typ =
30+
let t : t Ctypes_static.structure typ =
2931
typedef (structure "_mongoc_database_t") "mongoc_database_t"
3032
end
3133

3234
module Client = struct
3335
type t
3436

35-
let t : t structure typ =
37+
let t : t Ctypes_static.structure typ =
3638
typedef (structure "_mongoc_client_t") "mongoc_client_t"
3739
(* Not sealing incomplete type. See
3840
https://github.com/yallop/ocaml-ctypes/issues/237 *)
@@ -41,14 +43,14 @@ module Types (F : Ctypes.TYPE) = struct
4143
module Collection = struct
4244
type t
4345

44-
let t : t structure typ =
46+
let t : t Ctypes_static.structure typ =
4547
typedef (structure "_mongoc_collection_t") "mongoc_collection_t"
4648
end
4749

4850
module Cursor = struct
4951
type t
5052

51-
let t : t structure typ =
53+
let t : t Ctypes_static.structure typ =
5254
typedef (structure "_mongoc_cursor_t") "mongoc_cursor_t"
5355
end
5456
end

0 commit comments

Comments
 (0)