Skip to content

Commit accaab5

Browse files
authored
Merge 81c2a6a into 0472024
2 parents 0472024 + 81c2a6a commit accaab5

File tree

8 files changed

+360
-242
lines changed

8 files changed

+360
-242
lines changed

ocaml/database/db_cache_impl.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ let db_get_by_uuid t tbl uuid_val =
240240
| _ ->
241241
raise (Too_many_values (tbl, "", uuid_val))
242242

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+
243258
(** Return reference fields from tbl that matches specified name_label field *)
244259
let db_get_by_name_label t tbl label =
245260
read_field_where t

ocaml/database/db_interface.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ module type DB_ACCESS = sig
5656
(** [db_get_by_uuid tbl uuid] returns the single object reference
5757
associated with [uuid] *)
5858

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+
5964
val db_get_by_name_label : Db_ref.t -> string -> string -> string list
6065
(** [db_get_by_name_label tbl label] returns the list of object references
6166
associated with [label] *)

ocaml/database/db_rpc_client_v1.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ functor
8888
do_remote_call marshall_db_get_by_uuid_args
8989
unmarshall_db_get_by_uuid_response "db_get_by_uuid" (t, u)
9090

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+
9195
let db_get_by_name_label _ t l =
9296
do_remote_call marshall_db_get_by_name_label_args
9397
unmarshall_db_get_by_name_label_response "db_get_by_name_label" (t, l)

ocaml/database/db_rpc_client_v2.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ functor
7777
| _ ->
7878
raise Remote_db_server_returned_bad_message
7979

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+
8087
let db_get_by_name_label _ t l =
8188
match process (Request.Db_get_by_name_label (t, l)) with
8289
| Response.Db_get_by_name_label y ->

ocaml/database/db_rpc_common_v1.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ let marshall_db_get_by_uuid_response s = XMLRPC.To.string s
194194

195195
let unmarshall_db_get_by_uuid_response xml = XMLRPC.From.string xml
196196

197+
let unmarshall_db_get_by_uuid_opt_response xml = unmarshall_stringopt xml
198+
197199
(* db_get_by_name_label *)
198200
let marshall_db_get_by_name_label_args (s1, s2) = marshall_2strings (s1, s2)
199201

ocaml/database/db_rpc_common_v2.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module Response = struct
5959
| Find_refs_with_filter of string list
6060
| Read_field_where of string list
6161
| Db_get_by_uuid of string
62+
| Db_get_by_uuid_opt of string option
6263
| Db_get_by_name_label of string list
6364
| Create_row of unit
6465
| Delete_row of unit

ocaml/idl/ocaml_backend/gen_db_actions.ml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ let dm_to_string tys : O.Module.t =
9393
"fun x -> x |> SecretString.rpc_of_t |> Rpc.string_of_rpc"
9494
| DT.Record _ ->
9595
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)"]
9699
| DT.Option _ ->
97100
failwith "option types never stored in the database"
98101
in
@@ -148,6 +151,13 @@ let string_to_dm tys : O.Module.t =
148151
"SecretString.of_string"
149152
| DT.Record _ ->
150153
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+
]
151161
| DT.Option _ ->
152162
failwith "option types never stored in the database"
153163
in
@@ -515,7 +525,32 @@ let db_action api : O.Module.t =
515525
(Escaping.escape_obj obj.DT.name)
516526
(OU.escape name)
517527
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+
)
519554
| _ ->
520555
failwith
521556
"GetByUuid call should have only one parameter and a result!"

0 commit comments

Comments
 (0)