|
| 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 |
0 commit comments