Skip to content

Commit f2e86c2

Browse files
committed
CP-307933: [prepare]: introduce DB_ACCESS2
This provides direct access to a Value.t when known, which avoids having to serialize and deserialize a Value.t just to read it. Not yet used, no functional change. Signed-off-by: Edwin Török <[email protected]>
1 parent db991bb commit f2e86c2

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

ocaml/database/db_interface.mli

+17-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ module type DB_ACCESS_FIELD = sig
9696

9797
type field_out
9898

99-
val read_field_where : Db_ref.t -> Db_cache_types.where_record -> field list
99+
val read_field_where :
100+
Db_ref.t -> Db_cache_types.where_record -> field_out list
100101
(** [read_field_where {tbl,return,where_field,where_value}] returns a
101102
list of the [return] fields in table [tbl] where the [where_field]
102103
equals [where_value] *)
@@ -106,11 +107,12 @@ module type DB_ACCESS_FIELD = sig
106107
(** [create_row tbl kvpairs ref] create a new row in [tbl] with
107108
key [ref] and contents [kvpairs] *)
108109

109-
val write_field : Db_ref.t -> table -> db_ref -> field_name -> field -> unit
110+
val write_field :
111+
Db_ref.t -> table -> db_ref -> field_name -> field_in -> unit
110112
(** [write_field context tbl ref fld val] changes field [fld] to [val] in
111113
row [ref] in table [tbl] *)
112114

113-
val read_field : Db_ref.t -> table -> field_name -> db_ref -> field
115+
val read_field : Db_ref.t -> table -> field_name -> db_ref -> field_out
114116
(** [read_field context tbl fld ref] returns the value of field [fld]
115117
in row [ref] in table [tbl] *)
116118

@@ -133,3 +135,15 @@ module type DB_ACCESS = sig
133135
include
134136
DB_ACCESS_FIELD with type field_in = string and type field_out = string
135137
end
138+
139+
module type DB_ACCESS2 = sig
140+
include DB_ACCESS_COMMON
141+
142+
include
143+
DB_ACCESS_FIELD
144+
with type field_in = Schema.Value.t
145+
and type field_out = Schema.maybe_cached_value
146+
147+
module Compat :
148+
DB_ACCESS_FIELD with type field_in = string and type field_out = string
149+
end

ocaml/database/db_interface_compat.ml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(*
2+
* Copyright (C) Cloud Software Group
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published
6+
* by the Free Software Foundation; version 2.1 only. with the special
7+
* exception on linking described in file LICENSE.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*)
14+
15+
open Db_interface
16+
17+
module OfCached (DB : DB_ACCESS2) : DB_ACCESS = struct
18+
include DB include DB.Compat
19+
end
20+
21+
module OfCompat (DB : DB_ACCESS) : DB_ACCESS2 = struct
22+
module Compat = DB
23+
include Compat
24+
25+
type field_in = Schema.Value.t
26+
27+
type field_out = Schema.maybe_cached_value
28+
29+
let field_of_compat = Schema.CachedValue.of_string
30+
31+
let compat_of_field = Schema.Value.marshal
32+
33+
let regular_field_of_compat (k, v) = (k, field_of_compat v)
34+
35+
let regular_fields_of_compat l = List.map regular_field_of_compat l
36+
37+
let compat_of_regular_field (k, v) = (k, compat_of_field v)
38+
39+
let compat_of_regular_fields l = List.map compat_of_regular_field l
40+
41+
let db_record_of_compat (regular, assoc) =
42+
(regular_fields_of_compat regular, assoc)
43+
44+
let db_record_entry_of_compat (ref, record) = (ref, db_record_of_compat record)
45+
46+
let read_field_where t where =
47+
read_field_where t where |> List.map field_of_compat
48+
49+
let create_row t tbl fields ref =
50+
create_row t tbl (compat_of_regular_fields fields) ref
51+
52+
let write_field t tbl ref fld field =
53+
write_field t tbl ref fld (compat_of_field field)
54+
55+
let read_field t tbl fld ref = read_field t tbl fld ref |> field_of_compat
56+
57+
let read_record t tbl ref = read_record t tbl ref |> db_record_of_compat
58+
59+
let read_records_where t tbl expr =
60+
read_records_where t tbl expr |> List.map db_record_entry_of_compat
61+
end
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(*
2+
* Copyright (C) Cloud Software Group
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published
6+
* by the Free Software Foundation; version 2.1 only. with the special
7+
* exception on linking described in file LICENSE.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*)
14+
open Db_interface
15+
16+
module OfCached : functor (_ : DB_ACCESS2) -> DB_ACCESS
17+
18+
module OfCompat : functor (_ : DB_ACCESS) -> DB_ACCESS2

0 commit comments

Comments
 (0)