forked from ermine/sulci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seen_sql.ml
299 lines (265 loc) · 10.6 KB
/
seen_sql.ml
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
(* DO NOT EDIT MANUALLY *)
(* *)
(* generated by sqlgg 0.2.3-49-g30df037 on 2010-01-14T17:45Z *)
module Make (T : Sqlgg_traits.M) = struct
let create_greeting db =
T.execute db "CREATE TABLE IF NOT EXISTS greeting (jid varchar, room varchar, msg varchar)" T.no_params
let create_index_gr_index db =
T.execute db "CREATE INDEX IF NOT EXISTS gr_index ON greeting (jid, room)" T.no_params
let check_greet db ~jid ~room =
let get_row stmt =
(T.get_column_Int stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT 1 FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
let add_greet db ~jid ~room ~msg =
let set_params stmt =
let p = T.start_params stmt 3 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.set_param_Text p 2 msg;
T.finish_params p
in
T.execute db "INSERT INTO greeting (jid, room, msg) VALUES (@jid,@room,@msg)" set_params
let update_greet db ~msg ~jid ~room =
let set_params stmt =
let p = T.start_params stmt 3 in
T.set_param_Text p 0 msg;
T.set_param_Text p 1 jid;
T.set_param_Text p 2 room;
T.finish_params p
in
T.execute db "UPDATE greeting SET msg=@msg WHERE jid=@jid AND room=@room" set_params
let get_greet db ~jid ~room =
let get_row stmt =
(T.get_column_Text stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT msg FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
let create_users db =
T.execute db "CREATE TABLE IF NOT EXISTS users (jid varchar, room varchar, nick varchar, last integer, action varchar, reason varchar)" T.no_params
let create_index_users_index db =
T.execute db "CREATE INDEX IF NOT EXISTS users_index ON users (jid, room)" T.no_params
let create_index_users_nicks db =
T.execute db "CREATE INDEX IF NOT EXISTS users_nicks ON users (nick, room)" T.no_params
let check_user_by_nick db ~nick ~room =
let get_row stmt =
(T.get_column_Int stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 nick;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT 1 FROM users WHERE nick=@nick AND room=@room LIMIT 1" set_params get_row
let update_user_by_nick db ~last ~action ~reason ~nick ~room =
let set_params stmt =
let p = T.start_params stmt 5 in
T.set_param_Int p 0 last;
T.set_param_Text p 1 action;
T.set_param_Text p 2 reason;
T.set_param_Text p 3 nick;
T.set_param_Text p 4 room;
T.finish_params p
in
T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE nick=@nick AND room=@room" set_params
let add_user_by_nick db ~jid ~room ~nick ~last ~action ~reason =
let set_params stmt =
let p = T.start_params stmt 6 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.set_param_Text p 2 nick;
T.set_param_Int p 3 last;
T.set_param_Text p 4 action;
T.set_param_Text p 5 reason;
T.finish_params p
in
T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
let check_user_by_jid db ~jid ~room =
let get_row stmt =
(T.get_column_Int stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT 1 FROM users WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
let update_user_by_jid db ~last ~action ~reason ~jid ~room =
let set_params stmt =
let p = T.start_params stmt 5 in
T.set_param_Int p 0 last;
T.set_param_Text p 1 action;
T.set_param_Text p 2 reason;
T.set_param_Text p 3 jid;
T.set_param_Text p 4 room;
T.finish_params p
in
T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE jid=@jid AND room=@room" set_params
let add_user_by_jid db ~jid ~room ~nick ~last ~action ~reason =
let set_params stmt =
let p = T.start_params stmt 6 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.set_param_Text p 2 nick;
T.set_param_Int p 3 last;
T.set_param_Text p 4 action;
T.set_param_Text p 5 reason;
T.finish_params p
in
T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
let seen_by_nick db ~nick ~room =
let get_row stmt =
(T.get_column_Text stmt 0), (T.get_column_Int stmt 1), (T.get_column_Text stmt 2), (T.get_column_Text stmt 3)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 nick;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT jid, last, action, reason FROM users WHERE nick=@nick AND room=@room ORDER BY last DESC LIMIT 1" set_params get_row
module Fold = struct
let create_greeting db =
T.execute db "CREATE TABLE IF NOT EXISTS greeting (jid varchar, room varchar, msg varchar)" T.no_params
let create_index_gr_index db =
T.execute db "CREATE INDEX IF NOT EXISTS gr_index ON greeting (jid, room)" T.no_params
let check_greet db ~jid ~room =
let get_row stmt =
(T.get_column_Int stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT 1 FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
let add_greet db ~jid ~room ~msg =
let set_params stmt =
let p = T.start_params stmt 3 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.set_param_Text p 2 msg;
T.finish_params p
in
T.execute db "INSERT INTO greeting (jid, room, msg) VALUES (@jid,@room,@msg)" set_params
let update_greet db ~msg ~jid ~room =
let set_params stmt =
let p = T.start_params stmt 3 in
T.set_param_Text p 0 msg;
T.set_param_Text p 1 jid;
T.set_param_Text p 2 room;
T.finish_params p
in
T.execute db "UPDATE greeting SET msg=@msg WHERE jid=@jid AND room=@room" set_params
let get_greet db ~jid ~room =
let get_row stmt =
(T.get_column_Text stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT msg FROM greeting WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
let create_users db =
T.execute db "CREATE TABLE IF NOT EXISTS users (jid varchar, room varchar, nick varchar, last integer, action varchar, reason varchar)" T.no_params
let create_index_users_index db =
T.execute db "CREATE INDEX IF NOT EXISTS users_index ON users (jid, room)" T.no_params
let create_index_users_nicks db =
T.execute db "CREATE INDEX IF NOT EXISTS users_nicks ON users (nick, room)" T.no_params
let check_user_by_nick db ~nick ~room =
let get_row stmt =
(T.get_column_Int stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 nick;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT 1 FROM users WHERE nick=@nick AND room=@room LIMIT 1" set_params get_row
let update_user_by_nick db ~last ~action ~reason ~nick ~room =
let set_params stmt =
let p = T.start_params stmt 5 in
T.set_param_Int p 0 last;
T.set_param_Text p 1 action;
T.set_param_Text p 2 reason;
T.set_param_Text p 3 nick;
T.set_param_Text p 4 room;
T.finish_params p
in
T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE nick=@nick AND room=@room" set_params
let add_user_by_nick db ~jid ~room ~nick ~last ~action ~reason =
let set_params stmt =
let p = T.start_params stmt 6 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.set_param_Text p 2 nick;
T.set_param_Int p 3 last;
T.set_param_Text p 4 action;
T.set_param_Text p 5 reason;
T.finish_params p
in
T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
let check_user_by_jid db ~jid ~room =
let get_row stmt =
(T.get_column_Int stmt 0)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT 1 FROM users WHERE jid=@jid AND room=@room LIMIT 1" set_params get_row
let update_user_by_jid db ~last ~action ~reason ~jid ~room =
let set_params stmt =
let p = T.start_params stmt 5 in
T.set_param_Int p 0 last;
T.set_param_Text p 1 action;
T.set_param_Text p 2 reason;
T.set_param_Text p 3 jid;
T.set_param_Text p 4 room;
T.finish_params p
in
T.execute db "UPDATE users SET last=@last, action=@action, reason=@reason WHERE jid=@jid AND room=@room" set_params
let add_user_by_jid db ~jid ~room ~nick ~last ~action ~reason =
let set_params stmt =
let p = T.start_params stmt 6 in
T.set_param_Text p 0 jid;
T.set_param_Text p 1 room;
T.set_param_Text p 2 nick;
T.set_param_Int p 3 last;
T.set_param_Text p 4 action;
T.set_param_Text p 5 reason;
T.finish_params p
in
T.execute db "INSERT INTO users (jid, room, nick, last, action, reason) VALUES (@jid,@room,@nick,@last,@action,@reason)" set_params
let seen_by_nick db ~nick ~room =
let get_row stmt =
(T.get_column_Text stmt 0), (T.get_column_Int stmt 1), (T.get_column_Text stmt 2), (T.get_column_Text stmt 3)
in
let set_params stmt =
let p = T.start_params stmt 2 in
T.set_param_Text p 0 nick;
T.set_param_Text p 1 room;
T.finish_params p
in
T.select1 db "SELECT jid, last, action, reason FROM users WHERE nick=@nick AND room=@room ORDER BY last DESC LIMIT 1" set_params get_row
end (* module Fold *)
end (* module Make *)