-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sql
More file actions
308 lines (253 loc) · 7.63 KB
/
install.sql
File metadata and controls
308 lines (253 loc) · 7.63 KB
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
300
301
302
303
304
305
306
307
308
BEGIN;
DROP SCHEMA IF EXISTS http CASCADE;
CREATE SCHEMA http;
CREATE FUNCTION http.get_args2(name1 text, name2 text, name3 text, name4 text, OUT name1 json) AS
'SELECT row_to_json(row(name1 , name2 , name3 , name4));'
LANGUAGE SQL;
CREATE FUNCTION http.get_db_stat(name1 text, name2 text, tabname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM hack_oregon_db_status
WHERE hack_oregon_db_status IS NOT NULL
ORDER BY hack_oregon_db_status DESC
LIMIT 10) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_searches(name1 text, name2 text, tabname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(select access_log.committee_id, date, committee_name
from access_log join working_committees
on access_log.committee_id = working_committees.committee_id) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_search_terms(name1 text, name2 text, tabname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(select * from search_log) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_all_documentation(name1 text, name2 text, commID text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM documentation) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_endpoint_faq(name1 text, name2 text, endpointName text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM documentation
WHERE endpoint_name like '%'||endpointName ||'%') qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_committee_data_by_id(name1 text, name2 text, commID text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
INSERT INTO access_log (committee_id, date)
VALUES (commID::integer, CURRENT_TIMESTAMP);
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM campaign_detail
WHERE filer_id=commID::integer
ORDER BY total DESC) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS http.get_candidate_in_by_state_by_id(name1 text, name2 text, cid text, name4 text);
CREATE FUNCTION http.get_candidate_in_by_state_by_id(name1 text, name2 text, cid text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT state, value
FROM candidate_by_state
where filer_id = cid::integer
and direction = 'in') qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS http.get_candidate_out_by_state_by_id(name1 text, name2 text, cid text, name4 text);
CREATE FUNCTION http.get_candidate_out_by_state_by_id(name1 text, name2 text, cid text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT state, value
FROM candidate_by_state
where filer_id = cid::integer
and direction = 'out') qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS http.get_competitors_from_name(name1 text, name2 text, cname text, name4 text);
CREATE FUNCTION http.get_competitors_from_name(name1 text, name2 text, cname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM campaign_detail
WHERE race IN
(SELECT race
FROM campaign_detail
WHERE candidate_name =cname)) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS http.get_competitors_from_filer_id(name1 text, name2 text, cname text, name4 text);
CREATE FUNCTION http.get_competitors_from_filer_id(name1 text, name2 text, cname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(
SELECT *
FROM campaign_detail
WHERE race IN
(SELECT race
FROM campaign_detail
WHERE filer_id = cname::integer)) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS http.get_candidate_in_by_state(name1 text, name2 text, cname text, name4 text);
CREATE FUNCTION http.get_candidate_in_by_state(name1 text, name2 text, cname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT state, value
FROM candidate_by_state
where candidate_name = cname
and direction = 'in') qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
DROP FUNCTION IF EXISTS http.get_candidate_out_by_state(name1 text, name2 text, cname text, name4 text);
CREATE FUNCTION http.get_candidate_out_by_state(name1 text, name2 text, cname text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT state, value
FROM candidate_by_state
where candidate_name = cname
and direction = 'out') qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_committee_map(name1 text, name2 text, numRec text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT candidate_name, committee_names, filer_id
FROM campaign_detail) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_top_committee_data(name1 text, name2 text, numRec text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM campaign_detail
ORDER BY total DESC
LIMIT numRec::int) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_committee_data(name1 text, name2 text, commName text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM campaign_detail
WHERE candidate_name=commName
ORDER BY total DESC) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_current_transactions(name1 text, name2 text, candidate_id text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM cc_working_transactions
WHERE filer_id = candidate_id::int
ORDER BY tran_date DESC) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get(aschema text, afunction text, apath text, auser text) RETURNS json AS $$
DECLARE
args text;
result json;
BEGIN
SELECT array_to_string(array_agg(
(SELECT quote_literal(a[1]) || coalesce('::' || b[2], '')
FROM regexp_split_to_array(row, E'::') AS a,
regexp_split_to_array(row, E'::') AS b)
), ',')
FROM unnest(regexp_split_to_array(apath, E'\/')) AS row INTO args;
args := format('SELECT * FROM %I.%I(%L, %s) as row;', aschema, 'get_' || afunction, auser, args);
RAISE NOTICE '%', args;
EXECUTE args into result;
RETURN result;
END;
$$ LANGUAGE plpgsql;
COMMIT;