/
dbset.opa
108 lines (96 loc) · 2.75 KB
/
dbset.opa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
/*
@authors ?
**/
/**
* Utility functions on dbset
*
* @category DATABASE
* @author Quentin Bourgerie
* @destination PUBLIC
* @stability Not stable
*/
/**
* {1 About this module}
*
* This module defines the primitive type of dbset and functions for
* manipulate this kind of data.
*
* {1 Where do I start?}
*
* {2 Path declaration}
*
* On the first step define a multiple keys path like that :
* [db /myset[a;b] : {a : int; b : string; c : int}]
*
* This declaration define a path to a dbset that contains data of
* type [{a : int; b : string; c : int}] indexed by the keys [a] and
* [b].
*
* {2 Data(s) access}
*
* Actually you can access to path by 2 ways, in the two case you
* access with a virtual path.
*
* On both ways the write access take a record that contains all
* fields of the stored data type unless the keys which are already
* binded.
*
*
* The read access differs if you give a full key, or just a partial
* key. Indeed if you give a full key the read returns a single value,
* else the read returns a dbset value.
*
* {3 Examples }
*
* {[
* /* Access with a full key */
* @/myset[a=1; b="opa"] : virtual_ref_path({a:int; b:string; c:int},
* {b:string; c : int})
* /* Access with a partial key */
* @/myset[a=1] : virtual_ref_path(dbset({a:int; b:string; c:int}),
* {b:string; c : int})
*
* /* And of course, all syntactic sugar on path works */
* !/myset[a=1; b="opa"] : virtual_val_path({a:int; b:string; c:int})
*
* !/myset[a=1] : virtual_val_path(dbset({a:int; b:string; c:int}))
*
* /myset[a=1; b="opa"] : {a:int; b:string; c:int}
*
* /myset[b="opa"] : dbset({a:int; b:string; c:int})
* }
*
* {1 What if I need more?}
*
* TODO (Access with range, etc.)
**/
/**
* {1 Types defined in this module}
*/
/**
* A database set that contains ['a] values
**/
@opacapi
type dbset('a) = external
/**
* {1 Interface}
*/
DbSet = {{
/**
* [DbSet.fold(dbset, acc, folder)] Fold on a [dbset].
*/
fold = %%badoplink_fold_dbset%% : dbset('a), 'acc, ('acc, 'a -> 'acc) -> 'acc
}}