File tree Expand file tree Collapse file tree 8 files changed +360
-242
lines changed Expand file tree Collapse file tree 8 files changed +360
-242
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,21 @@ let db_get_by_uuid t tbl uuid_val =
240
240
| _ ->
241
241
raise (Too_many_values (tbl, " " , uuid_val))
242
242
243
+ let db_get_by_uuid_opt t tbl uuid_val =
244
+ match
245
+ read_field_where t
246
+ {
247
+ table= tbl
248
+ ; return= Db_names. ref
249
+ ; where_field= Db_names. uuid
250
+ ; where_value= uuid_val
251
+ }
252
+ with
253
+ | [r] ->
254
+ Some r
255
+ | _ ->
256
+ None
257
+
243
258
(* * Return reference fields from tbl that matches specified name_label field *)
244
259
let db_get_by_name_label t tbl label =
245
260
read_field_where t
Original file line number Diff line number Diff line change @@ -56,6 +56,11 @@ module type DB_ACCESS = sig
56
56
(* * [db_get_by_uuid tbl uuid] returns the single object reference
57
57
associated with [uuid] *)
58
58
59
+ val db_get_by_uuid_opt : Db_ref .t -> string -> string -> string option
60
+ (* * [db_get_by_uuid_opt tbl uuid] returns [Some obj] with the single object
61
+ reference associated with [uuid] if one exists and [None] otherwise,
62
+ instead of raising an exception like [get_by_uuid] *)
63
+
59
64
val db_get_by_name_label : Db_ref .t -> string -> string -> string list
60
65
(* * [db_get_by_name_label tbl label] returns the list of object references
61
66
associated with [label] *)
Original file line number Diff line number Diff line change @@ -88,6 +88,10 @@ functor
88
88
do_remote_call marshall_db_get_by_uuid_args
89
89
unmarshall_db_get_by_uuid_response " db_get_by_uuid" (t, u)
90
90
91
+ let db_get_by_uuid_opt _ t u =
92
+ do_remote_call marshall_db_get_by_uuid_args
93
+ unmarshall_db_get_by_uuid_opt_response " db_get_by_uuid_opt" (t, u)
94
+
91
95
let db_get_by_name_label _ t l =
92
96
do_remote_call marshall_db_get_by_name_label_args
93
97
unmarshall_db_get_by_name_label_response " db_get_by_name_label" (t, l)
Original file line number Diff line number Diff line change @@ -77,6 +77,13 @@ functor
77
77
| _ ->
78
78
raise Remote_db_server_returned_bad_message
79
79
80
+ let db_get_by_uuid_opt _ t u =
81
+ match process (Request. Db_get_by_uuid (t, u)) with
82
+ | Response. Db_get_by_uuid_opt y ->
83
+ y
84
+ | _ ->
85
+ raise Remote_db_server_returned_bad_message
86
+
80
87
let db_get_by_name_label _ t l =
81
88
match process (Request. Db_get_by_name_label (t, l)) with
82
89
| Response. Db_get_by_name_label y ->
Original file line number Diff line number Diff line change @@ -194,6 +194,8 @@ let marshall_db_get_by_uuid_response s = XMLRPC.To.string s
194
194
195
195
let unmarshall_db_get_by_uuid_response xml = XMLRPC.From. string xml
196
196
197
+ let unmarshall_db_get_by_uuid_opt_response xml = unmarshall_stringopt xml
198
+
197
199
(* db_get_by_name_label *)
198
200
let marshall_db_get_by_name_label_args (s1 , s2 ) = marshall_2strings (s1, s2)
199
201
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ module Response = struct
59
59
| Find_refs_with_filter of string list
60
60
| Read_field_where of string list
61
61
| Db_get_by_uuid of string
62
+ | Db_get_by_uuid_opt of string option
62
63
| Db_get_by_name_label of string list
63
64
| Create_row of unit
64
65
| Delete_row of unit
Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ let dm_to_string tys : O.Module.t =
93
93
" fun x -> x |> SecretString.rpc_of_t |> Rpc.string_of_rpc"
94
94
| DT. Record _ ->
95
95
failwith " record types never stored in the database"
96
+ | DT. Option (DT. Ref _ as ty ) ->
97
+ String. concat " "
98
+ [" fun s -> set " ; OU. alias_of_ty ty; " (Option.to_list s)" ]
96
99
| DT. Option _ ->
97
100
failwith " option types never stored in the database"
98
101
in
@@ -148,6 +151,13 @@ let string_to_dm tys : O.Module.t =
148
151
" SecretString.of_string"
149
152
| DT. Record _ ->
150
153
failwith " record types never stored in the database"
154
+ | DT. Option (DT. Ref _ as ty ) ->
155
+ String. concat " "
156
+ [
157
+ " fun s -> match set "
158
+ ; OU. alias_of_ty ty
159
+ ; " s with [] -> None | x::_ -> Some x"
160
+ ]
151
161
| DT. Option _ ->
152
162
failwith " option types never stored in the database"
153
163
in
@@ -515,7 +525,32 @@ let db_action api : O.Module.t =
515
525
(Escaping. escape_obj obj.DT. name)
516
526
(OU. escape name)
517
527
in
518
- _string_to_dm ^ " ." ^ OU. alias_of_ty result_ty ^ " (" ^ query ^ " )"
528
+ let func =
529
+ _string_to_dm
530
+ ^ " ."
531
+ ^ OU. alias_of_ty result_ty
532
+ ^ " ("
533
+ ^ query
534
+ ^ " )"
535
+ in
536
+ let query_opt =
537
+ Printf. sprintf " DB.db_get_by_uuid_opt __t \" %s\" %s"
538
+ (Escaping. escape_obj obj.DT. name)
539
+ (OU. escape name)
540
+ in
541
+ String. concat " \n\t\t "
542
+ ([func]
543
+ @ [
544
+ String. concat " \n\t\t "
545
+ ([" and get_by_uuid_opt ~__context ~uuid =" ]
546
+ @ open_db_module
547
+ @ [
548
+ Printf. sprintf " Option.map %s.%s (%s)" _string_to_dm
549
+ (OU. alias_of_ty result_ty) query_opt
550
+ ]
551
+ )
552
+ ]
553
+ )
519
554
| _ ->
520
555
failwith
521
556
" GetByUuid call should have only one parameter and a result!"
You can’t perform that action at this time.
0 commit comments