-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.sql
More file actions
367 lines (307 loc) · 9.02 KB
/
Copy pathquery.sql
File metadata and controls
367 lines (307 loc) · 9.02 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
-- name: EntryById :one
SELECT * FROM entries WHERE id = $1 LIMIT 1;
-- name: EntryByIdForUpdate :one
SELECT * FROM entries WHERE id = $1 LIMIT 1 FOR UPDATE;
-- name: EntryBySymbolForUpdate :one
SELECT e.* FROM entries e, symbols s WHERE e.id = s.owner AND s.authority = @authority AND s.symbol = @symbol LIMIT 1 FOR UPDATE OF e;
-- name: EntryBySymbol :one
SELECT e.* FROM entries e, symbols s WHERE e.id = s.owner AND s.authority = @authority AND s.symbol = @symbol LIMIT 1;
-- name: GetConsortialEntry :one
SELECT * FROM entries WHERE type = 'Consortium' LIMIT 1;
-- name: EntriesByParent :many
SELECT * FROM entries WHERE parent = @parent;
-- name: LockConsortiumEntryChanges :exec
SELECT pg_advisory_xact_lock(hashtextextended('directoryish:consortium-entry', 0));
-- name: CreateEntry :one
INSERT INTO entries (
name, description, contact_name, email, phone_number, time_zone, organization_id, type, parent, lms_location_code, lender_of_last_resort
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
)
RETURNING *;
-- name: UpdateEntry :exec
UPDATE entries
SET
name = @name,
description = @description,
contact_name = @contact_name,
email = @email,
phone_number = @phone_number,
time_zone = @time_zone,
organization_id = @organization_id,
type = @type,
parent = @parent,
lms_location_code = @lms_location_code,
lender_of_last_resort = @lender_of_last_resort,
hrid = @hrid
WHERE id = @id;
-- name: DeleteEntryById :exec
DELETE from entries WHERE id = @id;
-- name: DeleteEntryBySymbol :exec
DELETE from entries USING symbols
WHERE entries.id = symbols.owner
AND symbols.authority = @authority
AND symbols.symbol = @symbol;
-- name: UpsertSymbol :one
INSERT INTO symbols (
id, owner, symbol, authority
) VALUES (
coalesce(sqlc.narg('id'), gen_random_uuid()),
@owner,
@symbol,
@authority
)
ON CONFLICT (id) DO UPDATE SET
owner = @owner,
symbol = @symbol,
authority = @authority
WHERE symbols.id = sqlc.narg('id')
RETURNING *;
-- name: DeleteOtherOwnedSymbols :exec
DELETE FROM symbols WHERE owner = @owner AND ID <> ALL(@ids::uuid[]);
-- name: DeleteAllOwnedSymbols :exec
DELETE FROM symbols WHERE owner = @owner;
-- name: UpsertServiceEndpoint :one
INSERT INTO service_endpoints (
id, entry, name, type, address
) VALUES (
coalesce(sqlc.narg('id'), gen_random_uuid()),
@entry,
@name,
@type,
@address
)
ON CONFLICT (id) DO UPDATE SET
entry = @entry,
name = @name,
type = @type,
address = @address
WHERE service_endpoints.id = sqlc.narg('id')
RETURNING *;
-- name: DeleteOtherOwnedServiceEndpoints :exec
DELETE FROM service_endpoints WHERE entry = @entry AND ID <> ALL(@ids::uuid[]);
-- name: DeleteAllOwnedServiceEndpoints :exec
DELETE FROM service_endpoints WHERE entry = @entry;
-- name: UpsertAddress :one
INSERT INTO addresses (
id, entry, type
) VALUES (
coalesce(sqlc.narg('id'), gen_random_uuid()),
@entry,
@type
)
ON CONFLICT (id) DO UPDATE SET
entry = @entry,
type = @type
WHERE addresses.id = sqlc.narg('id')
RETURNING *;
-- name: DeleteOtherOwnedAddresses :exec
DELETE FROM addresses WHERE entry = @entry AND ID <> ALL(@ids::uuid[]);
-- name: DeleteAllOwnedAddresses :exec
DELETE FROM addresses WHERE entry = @entry;
-- name: CreateAddressComponent :one
INSERT INTO address_components (
address, seq, type, value
) VALUES (
@address,
@seq,
@type,
@value
)
RETURNING *;
-- name: DeleteAllOwnedAddressComponents :exec
DELETE FROM address_components WHERE address = @address;
-- name: CreateTier :one
INSERT INTO tiers (
name, consortium, level, type, cost
) VALUES (
@name, @consortium, @level, @type, @cost
)
RETURNING *;
-- name: CreateNetwork :one
INSERT INTO networks (
name, consortium, priority
) VALUES (
@name, @consortium, @priority
)
RETURNING *;
-- name: UpdateNetwork :exec
UPDATE networks
SET
consortium = @consortium,
name = @name,
priority = @priority
WHERE id = @id;
-- name: UpdateTier :exec
UPDATE tiers
SET
consortium = @consortium,
name = @name,
level = @level,
type = @type,
cost = @cost
WHERE id = @id;
-- name: CreateEntryNetwork :one
INSERT INTO entry_networks (
entry, network
) VALUES (
@entry,
@network
)
RETURNING *;
-- name: CreateEntryTier :one
INSERT INTO entry_tiers (
entry, tier
) VALUES (
@entry,
@tier
)
RETURNING *;
-- name: CreateClosure :one
INSERT INTO closures (
entry, start_date, end_date, reason
) VALUES (
@entry,
@start_date,
@end_date,
@reason
)
RETURNING *;
-- name: UpsertLMSConfig :one
INSERT INTO lms_configs (
id, entry, address, from_agency, from_agency_authentication, to_agency, lookup_user_enabled,
accept_item_enabled, checkin_item_enabled, checkout_item_enabled, item_location,
request_item_request_type, request_item_scope_type, request_item_bib_code,
request_item_pickup_location_enabled, requester_pickup_location, supplier_pickup_location,
requester_patron_pattern
) VALUES (
coalesce(sqlc.narg('id'), gen_random_uuid()),
@entry,
@address,
@from_agency,
@from_agency_authentication,
@to_agency,
@lookup_user_enabled,
@accept_item_enabled,
@checkin_item_enabled,
@checkout_item_enabled,
@item_location,
@request_item_request_type,
@request_item_scope_type,
@request_item_bib_code,
@request_item_pickup_location_enabled,
@requester_pickup_location,
@supplier_pickup_location,
@requester_patron_pattern
)
ON CONFLICT (entry) DO UPDATE SET
address = @address,
from_agency = @from_agency,
from_agency_authentication = @from_agency_authentication,
to_agency = @to_agency,
lookup_user_enabled = @lookup_user_enabled,
accept_item_enabled = @accept_item_enabled,
checkin_item_enabled = @checkin_item_enabled,
checkout_item_enabled = @checkout_item_enabled,
item_location = @item_location,
request_item_request_type = @request_item_request_type,
request_item_scope_type = @request_item_scope_type,
request_item_bib_code = @request_item_bib_code,
request_item_pickup_location_enabled = @request_item_pickup_location_enabled,
requester_pickup_location = @requester_pickup_location,
supplier_pickup_location = @supplier_pickup_location,
requester_patron_pattern = @requester_patron_pattern
WHERE lms_configs.entry = sqlc.narg('entry')
RETURNING *;
-- name: GetNetworkById :one
SELECT * FROM networks WHERE id = $1 LIMIT 1;
-- name: GetNetworkByIdForUpdate :one
SELECT * FROM networks WHERE id = $1 LIMIT 1 FOR UPDATE;
-- name: GetTierById :one
SELECT * FROM tiers WHERE id = $1 LIMIT 1;
-- name: GetTierByIdForUpdate :one
SELECT * FROM tiers WHERE id = $1 LIMIT 1 FOR UPDATE;
-- name: GetEntryNetworkById :one
SELECT * FROM entry_networks WHERE id = $1 LIMIT 1;
-- name: GetEntryNetworkByNetworkAndEntry :one
SELECT * FROM entry_networks WHERE network = $1 AND entry = $2 LIMIT 1;
-- name: GetEntryTierById :one
SELECT * FROM entry_tiers WHERE id = $1 LIMIT 1;
-- name: GetEntryTierByTierAndEntry :one
SELECT * FROM entry_tiers WHERE tier = $1 AND entry = $2 LIMIT 1;
-- name: GetClosureById :one
SELECT * FROM closures WHERE id = $1 LIMIT 1;
-- name: GetClosureByIdForUpdate :one
SELECT * FROM closures WHERE id = $1 LIMIT 1 FOR UPDATE;
-- name: DeleteNetworkById :exec
DELETE from networks where id = @id;
-- name: DeleteTierById :exec
DELETE from tiers where id = @id;
-- name: DeleteEntryNetworkById :exec
DELETE from entry_networks WHERE id = @id;
-- name: DeleteEntryTierById :exec
DELETE from entry_tiers WHERE id = @id;
-- name: DeleteClosureById :exec
DELETE from closures where id = @id;
-- name: UpdateClosure :exec
UPDATE closures
SET
start_date = @start_date,
end_date = @end_date,
reason = @reason
WHERE id = @id;
-- name: ListNetworks :many
SELECT * FROM networks
LIMIT sqlc.arg('limit')
OFFSET sqlc.arg('offset');
-- name: ListNetworksForEntry :many
SELECT * FROM networks n
JOIN entry_networks en ON n.id = en.network
WHERE en.entry = $1;
-- name: ListNetworksForConsortium :many
SELECT * FROM networks
WHERE consortium = $1;
-- name: ListTiers :many
SELECT * FROM tiers
LIMIT sqlc.arg('limit')
OFFSET sqlc.arg('offset');
-- name: ListTiersForEntry :many
SELECT * FROM tiers t
JOIN entry_tiers et ON t.id = et.tier
WHERE et.entry = $1;
-- name: ListTiersForConsortium :many
SELECT * FROM tiers
WHERE consortium = $1;
-- name: ListClosures :many
SELECT * FROM closures
LIMIT sqlc.arg('limit')
OFFSET sqlc.arg('offset');
-- name: ListEntryNetworks :many
SELECT * FROM entry_networks
WHERE (
sqlc.narg('field')::text IS NULL
OR sqlc.narg('value')::text IS NULL
OR CASE sqlc.narg('field')::text
WHEN 'id' THEN id::text
WHEN 'entry' THEN entry::text
WHEN 'network' THEN network::text
END = sqlc.narg('value')::text
)
LIMIT sqlc.arg('limit')
OFFSET sqlc.arg('offset');
-- name: ListEntryTiers :many
SELECT * FROM entry_tiers
WHERE (
sqlc.narg('field')::text IS NULL
OR sqlc.narg('value')::text IS NULL
OR CASE sqlc.narg('field')::text
WHEN 'id' THEN id::text
WHEN 'entry' THEN entry::text
WHEN 'tier' THEN tier::text
END = sqlc.narg('value')::text
)
LIMIT sqlc.arg('limit')
OFFSET sqlc.arg('offset');
-- name: GetLMSConfigByEntry :one
SELECT * FROM lms_configs
WHERE entry = @entry;