diff --git a/ocaml/database/db_cache_impl.ml b/ocaml/database/db_cache_impl.ml index b4f23b0af0..46e4ff84f2 100644 --- a/ocaml/database/db_cache_impl.ml +++ b/ocaml/database/db_cache_impl.ml @@ -256,7 +256,7 @@ let read_refs t tblname = Table.fold (fun r _ _ acc -> r :: acc) tbl [] (* Return a list of all the refs for which the expression returns true. *) -let find_refs_with_filter_internal db (tblname : string) +let find_refs_with_filter_internal db (tblname : Db_interface.table) (expr : Db_filter_types.expr) = let tbl = TableSet.find tblname (Database.tableset db) in let eval_val row = function diff --git a/ocaml/database/db_interface.ml b/ocaml/database/db_interface.ml index 834c12cd8a..9e650ac244 100644 --- a/ocaml/database/db_interface.ml +++ b/ocaml/database/db_interface.ml @@ -23,8 +23,22 @@ module type RPC = sig (** [rpc request] transmits [request] and receives a response *) end +type table = string + +type field_name = string + +type field = string + +type db_ref = string + +type uuid = string + +type regular_fields = (field_name * field) list + +type associated_fields = (field_name * db_ref list) list + (** dictionary of regular fields x dictionary of associated set_ref values *) -type db_record = (string * string) list * (string * string list) list +type db_record = regular_fields * associated_fields (** The client interface to the database *) module type DB_ACCESS = sig @@ -32,65 +46,64 @@ module type DB_ACCESS = sig (** [initialise ()] must be called before any other function in this interface *) - val get_table_from_ref : Db_ref.t -> string -> string option - (** [get_table_from_ref ref] returns [Some tbl] if [ref] is a + val get_table_from_ref : Db_ref.t -> db_ref -> table option + (** [get_table_from_ref ref tbl] returns [Some tbl] if [ref] is a valid reference; None otherwise *) - val is_valid_ref : Db_ref.t -> string -> bool + val is_valid_ref : Db_ref.t -> db_ref -> bool (** [is_valid_ref ref] returns true if [ref] is valid; false otherwise *) - val read_refs : Db_ref.t -> string -> string list + val read_refs : Db_ref.t -> table -> db_ref list (** [read_refs tbl] returns a list of all references in table [tbl] *) val find_refs_with_filter : - Db_ref.t -> string -> Db_filter_types.expr -> string list + Db_ref.t -> table -> Db_filter_types.expr -> db_ref list (** [find_refs_with_filter tbl expr] returns a list of all references to rows which match [expr] *) - val read_field_where : Db_ref.t -> Db_cache_types.where_record -> string list + val read_field_where : Db_ref.t -> Db_cache_types.where_record -> field list (** [read_field_where {tbl,return,where_field,where_value}] returns a list of the [return] fields in table [tbl] where the [where_field] equals [where_value] *) - val db_get_by_uuid : Db_ref.t -> string -> string -> string + val db_get_by_uuid : Db_ref.t -> table -> uuid -> db_ref (** [db_get_by_uuid tbl uuid] returns the single object reference associated with [uuid] *) - val db_get_by_name_label : Db_ref.t -> string -> string -> string list + val db_get_by_name_label : Db_ref.t -> table -> string -> db_ref list (** [db_get_by_name_label tbl label] returns the list of object references associated with [label] *) - val create_row : - Db_ref.t -> string -> (string * string) list -> string -> unit + val create_row : Db_ref.t -> table -> regular_fields -> db_ref -> unit (** [create_row tbl kvpairs ref] create a new row in [tbl] with key [ref] and contents [kvpairs] *) - val delete_row : Db_ref.t -> string -> string -> unit + val delete_row : Db_ref.t -> db_ref -> table -> unit (** [delete_row context tbl ref] deletes row [ref] from table [tbl] *) - val write_field : Db_ref.t -> string -> string -> string -> string -> unit + val write_field : Db_ref.t -> table -> db_ref -> field_name -> field -> unit (** [write_field context tbl ref fld val] changes field [fld] to [val] in row [ref] in table [tbl] *) - val read_field : Db_ref.t -> string -> string -> string -> string + val read_field : Db_ref.t -> table -> db_ref -> field_name -> field (** [read_field context tbl ref fld] returns the value of field [fld] in row [ref] in table [tbl] *) - val read_record : Db_ref.t -> string -> string -> db_record + val read_record : Db_ref.t -> table -> db_ref -> db_record (** [read_record tbl ref] returns [ (field, value) ] * [ (set_ref fieldname * [ ref ]) ] *) val read_records_where : - Db_ref.t -> string -> Db_filter_types.expr -> (string * db_record) list + Db_ref.t -> table -> Db_filter_types.expr -> (db_ref * db_record) list (** [read_records_where tbl expr] returns a list of the values returned by read_record that match the expression *) val process_structured_field : Db_ref.t - -> string * string - -> string - -> string - -> string + -> field_name * field + -> table + -> field_name + -> db_ref -> Db_cache_types.structured_op_t -> unit (** [process_structured_field context kv tbl fld ref op] modifies the diff --git a/ocaml/tests/dune b/ocaml/tests/dune index ce8fe96c19..f2c5cfc5ba 100644 --- a/ocaml/tests/dune +++ b/ocaml/tests/dune @@ -64,6 +64,7 @@ (modules suite_alcotest_server test_client test_valid_ref_list test_vm_group) (libraries alcotest + xapi_database httpsvr tests_common xapi-client diff --git a/ocaml/xapi/dune b/ocaml/xapi/dune index fd539b66df..ce462392de 100644 --- a/ocaml/xapi/dune +++ b/ocaml/xapi/dune @@ -224,7 +224,7 @@ (name xapi_internal_server_only) (modes best) (modules server) - (libraries xapi_internal_minimal http_lib rpclib.core xapi-types xapi-log xapi-stdext-encodings xapi-consts xapi-backtrace xapi-stdext-date rpclib.json) + (libraries xapi_database xapi_internal_minimal http_lib rpclib.core xapi-types xapi-log xapi-stdext-encodings xapi-consts xapi-backtrace xapi-stdext-date rpclib.json) (wrapped false) )