-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathdb.mli
133 lines (110 loc) · 3.1 KB
/
db.mli
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
open Core
open Libexecution
(* Low-level API *)
type param =
| Int of int
| Int63 of Int63.t
| ID of Types.id
| String of string
| Uuid of Uuidm.t
| Float of float
| Binary of string
(* only works for passed params *)
| Secret of string
| RoundtrippableDval of Types.RuntimeT.dval
| RoundtrippableDvalmap of Types.RuntimeT.dval_map
(* Queryable are stored as jsonb so that they can be queried. *)
| QueryableDval of Types.RuntimeT.dval
| QueryableDvalmap of Types.RuntimeT.dval_map
| Time of Types.RuntimeT.time
| Null
| List of param list
| Bool of bool
[@@deriving show]
(* only works for in-script params *)
type result =
| TextResult
(* bytea will be returned as hex strings *)
| BinaryResult
(* unparsed binary data *)
(* NOTE: run is not allowed to receive multiple commands. If you
* want multiple statements, use [transaction] *)
val run :
params:param list
-> ?result:result
-> name:string
-> ?subject:string
-> string
-> unit
val transaction : name:string -> (unit -> unit) -> unit
val delete :
params:param list
-> ?result:result
-> name:string
-> ?subject:string
-> string
-> int
val fetch :
params:param list
-> ?result:result
-> name:string
-> ?subject:string
-> string
-> string list list
val fetch_one :
params:param list
-> ?result:result
-> name:string
-> ?subject:string
-> string
-> string list
(** This is fetch_one, but with SQL returning a single int field. The intent is
* to make it easy to swap Db.fetch_count and Db.delete so we can evaluate the
* performance of GC queries using fetch_count, with basically the same code as
* we use for delete - see Stored_events.trim_events_for_handler for an example. *)
val fetch_count :
params:param list
-> ?result:result
-> name:string
-> ?subject:string
-> string
-> int
val fetch_one_option :
params:param list
-> ?result:result
-> name:string
-> ?subject:string
-> string
-> string list option
val iter_with_cursor :
name:string
-> params:param list
-> ?result:result
-> f:(string list -> unit)
-> string
-> unit
val exists :
params:param list -> name:string -> ?subject:string -> string -> bool
(* Occasionally, we're trying to do something dynamic, or maybe multiple
* things in a single sql statement and then the above statements don't
* work, so we need to escape manually *)
val escape : param -> string
val escape_string : string -> string
val array_separator : string
val date_of_sqlstring : string -> Core_kernel.Time.t
(* Misc *)
val delete_benchmarking_data : unit -> unit
exception DBQueryException of string
val dbQueryExceptionToString : exn -> string
type table_stats_row =
{ relation : string
; disk_bytes : int
; rows : int
; disk_human : string
; rows_human : string }
(** Queries the database to get approximate sizes (both in bytes and in # of rows) for each
* table in the postgres DB, as a list of [table_stats_rows].
*
* Primary use case here is to run in a cron and be logged to honeycomb, but
* there is also human-readable output. *)
val table_stats : unit -> table_stats_row list