-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.sql.go
2412 lines (2152 loc) · 55.5 KB
/
query.sql.go
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.25.0
// source: query.sql
package postgres
import (
"context"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
const acquireTXLock = `-- name: AcquireTXLock :exec
SELECT pg_advisory_xact_lock($1::bigint)
`
func (q *Queries) AcquireTXLock(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, acquireTXLock, id)
return err
}
const activateSchema = `-- name: ActivateSchema :exec
INSERT INTO active_schemas(name, version)
VALUES ($1, $2)
ON CONFLICT(name) DO UPDATE SET
version = $2
`
type ActivateSchemaParams struct {
Name string
Version string
}
func (q *Queries) ActivateSchema(ctx context.Context, arg ActivateSchemaParams) error {
_, err := q.db.Exec(ctx, activateSchema, arg.Name, arg.Version)
return err
}
const checkMetaDocumentType = `-- name: CheckMetaDocumentType :one
SELECT coalesce(meta_type, ''), NOT d.main_doc IS NULL as is_meta_doc
FROM document AS d
LEFT JOIN meta_type_use AS m ON m.main_type = d.type
WHERE d.uuid = $1
`
type CheckMetaDocumentTypeRow struct {
MetaType string
IsMetaDoc pgtype.Bool
}
func (q *Queries) CheckMetaDocumentType(ctx context.Context, argUuid uuid.UUID) (CheckMetaDocumentTypeRow, error) {
row := q.db.QueryRow(ctx, checkMetaDocumentType, argUuid)
var i CheckMetaDocumentTypeRow
err := row.Scan(&i.MetaType, &i.IsMetaDoc)
return i, err
}
const checkPermissions = `-- name: CheckPermissions :one
SELECT (acl.uri IS NOT NULL) = true AS has_access
FROM document AS d
LEFT JOIN acl
ON (acl.uuid = d.uuid OR acl.uuid = d.main_doc)
AND acl.uri = ANY($1::text[])
AND $2::text[] && permissions
WHERE d.uuid = $3
`
type CheckPermissionsParams struct {
URI []string
Permissions []string
UUID uuid.UUID
}
func (q *Queries) CheckPermissions(ctx context.Context, arg CheckPermissionsParams) (bool, error) {
row := q.db.QueryRow(ctx, checkPermissions, arg.URI, arg.Permissions, arg.UUID)
var has_access bool
err := row.Scan(&has_access)
return has_access, err
}
const cleanUpAssignees = `-- name: CleanUpAssignees :exec
DELETE FROM planning_assignee
WHERE assignment = $1 AND version != $2
`
type CleanUpAssigneesParams struct {
Assignment uuid.UUID
Version int64
}
func (q *Queries) CleanUpAssignees(ctx context.Context, arg CleanUpAssigneesParams) error {
_, err := q.db.Exec(ctx, cleanUpAssignees, arg.Assignment, arg.Version)
return err
}
const cleanUpAssignments = `-- name: CleanUpAssignments :exec
DELETE FROM planning_assignment
WHERE planning_item = $1 AND version != $2
`
type CleanUpAssignmentsParams struct {
PlanningItem uuid.UUID
Version int64
}
func (q *Queries) CleanUpAssignments(ctx context.Context, arg CleanUpAssignmentsParams) error {
_, err := q.db.Exec(ctx, cleanUpAssignments, arg.PlanningItem, arg.Version)
return err
}
const cleanUpDeliverables = `-- name: CleanUpDeliverables :exec
DELETE FROM planning_deliverable
WHERE assignment = $1 AND version != $2
`
type CleanUpDeliverablesParams struct {
Assignment uuid.UUID
Version int64
}
func (q *Queries) CleanUpDeliverables(ctx context.Context, arg CleanUpDeliverablesParams) error {
_, err := q.db.Exec(ctx, cleanUpDeliverables, arg.Assignment, arg.Version)
return err
}
const configureEventsink = `-- name: ConfigureEventsink :exec
INSERT INTO eventsink(name, configuration) VALUES($1, $2)
ON CONFLICT (name) DO UPDATE SET
configuration = $2
`
type ConfigureEventsinkParams struct {
Name string
Config []byte
}
func (q *Queries) ConfigureEventsink(ctx context.Context, arg ConfigureEventsinkParams) error {
_, err := q.db.Exec(ctx, configureEventsink, arg.Name, arg.Config)
return err
}
const createDocumentVersion = `-- name: CreateDocumentVersion :exec
INSERT INTO document_version(
uuid, version,
created, creator_uri, meta, document_data, archived
) VALUES (
$1, $2,
$3, $4, $5, $6, false
)
`
type CreateDocumentVersionParams struct {
UUID uuid.UUID
Version int64
Created pgtype.Timestamptz
CreatorUri string
Meta []byte
DocumentData []byte
}
func (q *Queries) CreateDocumentVersion(ctx context.Context, arg CreateDocumentVersionParams) error {
_, err := q.db.Exec(ctx, createDocumentVersion,
arg.UUID,
arg.Version,
arg.Created,
arg.CreatorUri,
arg.Meta,
arg.DocumentData,
)
return err
}
const createStatusHead = `-- name: CreateStatusHead :exec
INSERT INTO status_heads(
uuid, name, type, version, current_id,
updated, updater_uri, language
) VALUES (
$1, $2, $3::text, $4::bigint, $5::bigint,
$6, $7, $8::text
)
ON CONFLICT (uuid, name) DO UPDATE
SET updated = $6,
updater_uri = $7,
current_id = $5::bigint,
version = $4::bigint,
language = $8::text
`
type CreateStatusHeadParams struct {
UUID uuid.UUID
Name string
Type string
Version int64
ID int64
Created pgtype.Timestamptz
CreatorUri string
Language string
}
func (q *Queries) CreateStatusHead(ctx context.Context, arg CreateStatusHeadParams) error {
_, err := q.db.Exec(ctx, createStatusHead,
arg.UUID,
arg.Name,
arg.Type,
arg.Version,
arg.ID,
arg.Created,
arg.CreatorUri,
arg.Language,
)
return err
}
const deactivateSchema = `-- name: DeactivateSchema :exec
DELETE FROM active_schemas
WHERE name = $1
`
func (q *Queries) DeactivateSchema(ctx context.Context, name string) error {
_, err := q.db.Exec(ctx, deactivateSchema, name)
return err
}
const deleteDocument = `-- name: DeleteDocument :exec
SELECT delete_document(
$1::uuid, $2::text, $3::bigint
)
`
type DeleteDocumentParams struct {
UUID uuid.UUID
URI string
RecordID int64
}
func (q *Queries) DeleteDocument(ctx context.Context, arg DeleteDocumentParams) error {
_, err := q.db.Exec(ctx, deleteDocument, arg.UUID, arg.URI, arg.RecordID)
return err
}
const deleteDocumentLock = `-- name: DeleteDocumentLock :execrows
DELETE FROM document_lock
WHERE uuid = $1
AND token = $2
`
type DeleteDocumentLockParams struct {
UUID uuid.UUID
Token string
}
func (q *Queries) DeleteDocumentLock(ctx context.Context, arg DeleteDocumentLockParams) (int64, error) {
result, err := q.db.Exec(ctx, deleteDocumentLock, arg.UUID, arg.Token)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const deleteExpiredDocumentLock = `-- name: DeleteExpiredDocumentLock :exec
DELETE FROM document_lock
WHERE uuid = ANY($1::uuid[])
AND expires < $2
`
type DeleteExpiredDocumentLockParams struct {
Uuids []uuid.UUID
Cutoff pgtype.Timestamptz
}
func (q *Queries) DeleteExpiredDocumentLock(ctx context.Context, arg DeleteExpiredDocumentLockParams) error {
_, err := q.db.Exec(ctx, deleteExpiredDocumentLock, arg.Uuids, arg.Cutoff)
return err
}
const deleteMetricKind = `-- name: DeleteMetricKind :exec
DELETE FROM metric_kind
WHERE name = $1
`
func (q *Queries) DeleteMetricKind(ctx context.Context, name string) error {
_, err := q.db.Exec(ctx, deleteMetricKind, name)
return err
}
const deletePlanningItem = `-- name: DeletePlanningItem :exec
DELETE FROM planning_item WHERE uuid = $1
`
func (q *Queries) DeletePlanningItem(ctx context.Context, argUuid uuid.UUID) error {
_, err := q.db.Exec(ctx, deletePlanningItem, argUuid)
return err
}
const deleteReport = `-- name: DeleteReport :exec
DELETE FROM report
WHERE name = $1
`
func (q *Queries) DeleteReport(ctx context.Context, name string) error {
_, err := q.db.Exec(ctx, deleteReport, name)
return err
}
const deleteStatusRule = `-- name: DeleteStatusRule :exec
DELETE FROM status_rule WHERE name = $1
`
func (q *Queries) DeleteStatusRule(ctx context.Context, name string) error {
_, err := q.db.Exec(ctx, deleteStatusRule, name)
return err
}
const dropACL = `-- name: DropACL :exec
DELETE FROM acl WHERE uuid = $1 AND uri = $2
`
type DropACLParams struct {
UUID uuid.UUID
URI string
}
func (q *Queries) DropACL(ctx context.Context, arg DropACLParams) error {
_, err := q.db.Exec(ctx, dropACL, arg.UUID, arg.URI)
return err
}
const dropMetaType = `-- name: DropMetaType :exec
DELETE FROM meta_type
WHERE meta_type = $1
`
func (q *Queries) DropMetaType(ctx context.Context, metaType string) error {
_, err := q.db.Exec(ctx, dropMetaType, metaType)
return err
}
const finaliseDelete = `-- name: FinaliseDelete :execrows
DELETE FROM document
WHERE uuid = $1 AND deleting = true
`
func (q *Queries) FinaliseDelete(ctx context.Context, argUuid uuid.UUID) (int64, error) {
result, err := q.db.Exec(ctx, finaliseDelete, argUuid)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getActiveSchema = `-- name: GetActiveSchema :one
SELECT s.name, s.version, s.spec
FROM active_schemas AS a
INNER JOIN document_schema AS s
ON s.name = a.name AND s.version = a.version
WHERE a.name = $1
`
func (q *Queries) GetActiveSchema(ctx context.Context, name string) (DocumentSchema, error) {
row := q.db.QueryRow(ctx, getActiveSchema, name)
var i DocumentSchema
err := row.Scan(&i.Name, &i.Version, &i.Spec)
return i, err
}
const getActiveSchemas = `-- name: GetActiveSchemas :many
SELECT s.name, s.version, s.spec
FROM active_schemas AS a
INNER JOIN document_schema AS s
ON s.name = a.name AND s.version = a.version
`
func (q *Queries) GetActiveSchemas(ctx context.Context) ([]DocumentSchema, error) {
rows, err := q.db.Query(ctx, getActiveSchemas)
if err != nil {
return nil, err
}
defer rows.Close()
var items []DocumentSchema
for rows.Next() {
var i DocumentSchema
if err := rows.Scan(&i.Name, &i.Version, &i.Spec); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getActiveStatuses = `-- name: GetActiveStatuses :many
SELECT name
FROM status
WHERE disabled = false
`
func (q *Queries) GetActiveStatuses(ctx context.Context) ([]string, error) {
rows, err := q.db.Query(ctx, getActiveStatuses)
if err != nil {
return nil, err
}
defer rows.Close()
var items []string
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
return nil, err
}
items = append(items, name)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getCompactedEventlog = `-- name: GetCompactedEventlog :many
SELECT
w.id, w.event, w.uuid, w.timestamp, w.type, w.version, w.status,
w.status_id, w.acl, w.updater, w.language, w.old_language, w.main_doc
FROM (
SELECT DISTINCT ON (
e.uuid,
CASE WHEN e.event = 'delete_document' THEN null ELSE 0 END,
CASE WHEN NOT e.old_language IS NULL THEN null ELSE 0 END
) id, event, uuid, timestamp, type, version, status, status_id, acl, updater, main_doc, language, old_language FROM eventlog AS e
WHERE e.id > $1 AND e.id <= $2
AND ($3::text IS NULL OR e.type = $3)
ORDER BY
e.uuid,
CASE WHEN e.event = 'delete_document' THEN null ELSE 0 END,
CASE WHEN NOT e.old_language IS NULL THEN null ELSE 0 END,
e.id DESC
) AS w
ORDER BY w.id ASC
LIMIT $5 OFFSET $4
`
type GetCompactedEventlogParams struct {
After int64
Until int64
Type pgtype.Text
RowOffset int32
RowLimit pgtype.Int4
}
type GetCompactedEventlogRow struct {
ID int64
Event string
UUID uuid.UUID
Timestamp pgtype.Timestamptz
Type pgtype.Text
Version pgtype.Int8
Status pgtype.Text
StatusID pgtype.Int8
Acl []byte
Updater pgtype.Text
Language pgtype.Text
OldLanguage pgtype.Text
MainDoc pgtype.UUID
}
func (q *Queries) GetCompactedEventlog(ctx context.Context, arg GetCompactedEventlogParams) ([]GetCompactedEventlogRow, error) {
rows, err := q.db.Query(ctx, getCompactedEventlog,
arg.After,
arg.Until,
arg.Type,
arg.RowOffset,
arg.RowLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetCompactedEventlogRow
for rows.Next() {
var i GetCompactedEventlogRow
if err := rows.Scan(
&i.ID,
&i.Event,
&i.UUID,
&i.Timestamp,
&i.Type,
&i.Version,
&i.Status,
&i.StatusID,
&i.Acl,
&i.Updater,
&i.Language,
&i.OldLanguage,
&i.MainDoc,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getDocumentACL = `-- name: GetDocumentACL :many
SELECT uuid, uri, permissions FROM acl WHERE uuid = $1
`
func (q *Queries) GetDocumentACL(ctx context.Context, argUuid uuid.UUID) ([]Acl, error) {
rows, err := q.db.Query(ctx, getDocumentACL, argUuid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Acl
for rows.Next() {
var i Acl
if err := rows.Scan(&i.UUID, &i.URI, &i.Permissions); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getDocumentData = `-- name: GetDocumentData :one
SELECT v.document_data, v.version
FROM document as d
INNER JOIN document_version AS v ON
v.uuid = d.uuid And v.version = d.current_version
WHERE d.uuid = $1
`
type GetDocumentDataRow struct {
DocumentData []byte
Version int64
}
func (q *Queries) GetDocumentData(ctx context.Context, argUuid uuid.UUID) (GetDocumentDataRow, error) {
row := q.db.QueryRow(ctx, getDocumentData, argUuid)
var i GetDocumentDataRow
err := row.Scan(&i.DocumentData, &i.Version)
return i, err
}
const getDocumentForDeletion = `-- name: GetDocumentForDeletion :one
SELECT uuid, current_version AS delete_record_id FROM document
WHERE deleting = true
ORDER BY created
FOR UPDATE SKIP LOCKED
LIMIT 1
`
type GetDocumentForDeletionRow struct {
UUID uuid.UUID
DeleteRecordID int64
}
func (q *Queries) GetDocumentForDeletion(ctx context.Context) (GetDocumentForDeletionRow, error) {
row := q.db.QueryRow(ctx, getDocumentForDeletion)
var i GetDocumentForDeletionRow
err := row.Scan(&i.UUID, &i.DeleteRecordID)
return i, err
}
const getDocumentForUpdate = `-- name: GetDocumentForUpdate :one
SELECT d.uri, d.type, d.current_version, d.deleting, d.main_doc, d.language,
l.uuid as lock_uuid, l.uri as lock_uri, l.created as lock_created,
l.expires as lock_expires, l.app as lock_app, l.comment as lock_comment,
l.token as lock_token
FROM document as d
LEFT JOIN document_lock as l ON d.uuid = l.uuid AND l.expires > $2
WHERE d.uuid = $1
FOR UPDATE OF d
`
type GetDocumentForUpdateParams struct {
UUID uuid.UUID
Now pgtype.Timestamptz
}
type GetDocumentForUpdateRow struct {
URI string
Type string
CurrentVersion int64
Deleting bool
MainDoc pgtype.UUID
Language pgtype.Text
LockUuid pgtype.UUID
LockUri pgtype.Text
LockCreated pgtype.Timestamptz
LockExpires pgtype.Timestamptz
LockApp pgtype.Text
LockComment pgtype.Text
LockToken pgtype.Text
}
func (q *Queries) GetDocumentForUpdate(ctx context.Context, arg GetDocumentForUpdateParams) (GetDocumentForUpdateRow, error) {
row := q.db.QueryRow(ctx, getDocumentForUpdate, arg.UUID, arg.Now)
var i GetDocumentForUpdateRow
err := row.Scan(
&i.URI,
&i.Type,
&i.CurrentVersion,
&i.Deleting,
&i.MainDoc,
&i.Language,
&i.LockUuid,
&i.LockUri,
&i.LockCreated,
&i.LockExpires,
&i.LockApp,
&i.LockComment,
&i.LockToken,
)
return i, err
}
const getDocumentHeads = `-- name: GetDocumentHeads :many
SELECT name, current_id
FROM status_heads
WHERE uuid = $1
`
type GetDocumentHeadsRow struct {
Name string
CurrentID int64
}
func (q *Queries) GetDocumentHeads(ctx context.Context, argUuid uuid.UUID) ([]GetDocumentHeadsRow, error) {
rows, err := q.db.Query(ctx, getDocumentHeads, argUuid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetDocumentHeadsRow
for rows.Next() {
var i GetDocumentHeadsRow
if err := rows.Scan(&i.Name, &i.CurrentID); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getDocumentInfo = `-- name: GetDocumentInfo :one
SELECT
d.uuid, d.uri, d.created, creator_uri, updated, updater_uri, current_version,
deleting, main_doc, l.uuid as lock_uuid, l.uri as lock_uri,
l.created as lock_created, l.expires as lock_expires, l.app as lock_app,
l.comment as lock_comment, l.token as lock_token
FROM document as d
LEFT JOIN document_lock as l ON d.uuid = l.uuid AND l.expires > $1
WHERE d.uuid = $2
`
type GetDocumentInfoParams struct {
Now pgtype.Timestamptz
UUID uuid.UUID
}
type GetDocumentInfoRow struct {
UUID uuid.UUID
URI string
Created pgtype.Timestamptz
CreatorUri string
Updated pgtype.Timestamptz
UpdaterUri string
CurrentVersion int64
Deleting bool
MainDoc pgtype.UUID
LockUuid pgtype.UUID
LockUri pgtype.Text
LockCreated pgtype.Timestamptz
LockExpires pgtype.Timestamptz
LockApp pgtype.Text
LockComment pgtype.Text
LockToken pgtype.Text
}
func (q *Queries) GetDocumentInfo(ctx context.Context, arg GetDocumentInfoParams) (GetDocumentInfoRow, error) {
row := q.db.QueryRow(ctx, getDocumentInfo, arg.Now, arg.UUID)
var i GetDocumentInfoRow
err := row.Scan(
&i.UUID,
&i.URI,
&i.Created,
&i.CreatorUri,
&i.Updated,
&i.UpdaterUri,
&i.CurrentVersion,
&i.Deleting,
&i.MainDoc,
&i.LockUuid,
&i.LockUri,
&i.LockCreated,
&i.LockExpires,
&i.LockApp,
&i.LockComment,
&i.LockToken,
)
return i, err
}
const getDocumentStatusForArchiving = `-- name: GetDocumentStatusForArchiving :one
SELECT
s.uuid, s.name, s.id, s.version, s.created, s.creator_uri, s.meta,
p.signature AS parent_signature, v.signature AS version_signature
FROM document_status AS s
INNER JOIN document_version AS v
ON v.uuid = s.uuid
AND v.version = s.version
AND v.signature IS NOT NULL
LEFT JOIN document_status AS p
ON p.uuid = s.uuid AND p.name = s.name AND p.id = s.id-1
WHERE s.archived = false
AND (s.id = 1 OR p.archived = true)
ORDER BY s.created
FOR UPDATE OF s SKIP LOCKED
LIMIT 1
`
type GetDocumentStatusForArchivingRow struct {
UUID uuid.UUID
Name string
ID int64
Version int64
Created pgtype.Timestamptz
CreatorUri string
Meta []byte
ParentSignature pgtype.Text
VersionSignature pgtype.Text
}
func (q *Queries) GetDocumentStatusForArchiving(ctx context.Context) (GetDocumentStatusForArchivingRow, error) {
row := q.db.QueryRow(ctx, getDocumentStatusForArchiving)
var i GetDocumentStatusForArchivingRow
err := row.Scan(
&i.UUID,
&i.Name,
&i.ID,
&i.Version,
&i.Created,
&i.CreatorUri,
&i.Meta,
&i.ParentSignature,
&i.VersionSignature,
)
return i, err
}
const getDocumentUnarchivedCount = `-- name: GetDocumentUnarchivedCount :one
SELECT SUM(num) FROM (
SELECT COUNT(*) as num
FROM document_status AS s
WHERE s.uuid = $1 AND s.archived = false
UNION
SELECT COUNT(*) as num
FROM document_version AS v
WHERE v.uuid = $1 AND v.archived = false
) AS unarchived
`
func (q *Queries) GetDocumentUnarchivedCount(ctx context.Context, argUuid uuid.UUID) (int64, error) {
row := q.db.QueryRow(ctx, getDocumentUnarchivedCount, argUuid)
var sum int64
err := row.Scan(&sum)
return sum, err
}
const getDocumentVersionData = `-- name: GetDocumentVersionData :one
SELECT document_data
FROM document_version
WHERE uuid = $1 AND version = $2
`
type GetDocumentVersionDataParams struct {
UUID uuid.UUID
Version int64
}
func (q *Queries) GetDocumentVersionData(ctx context.Context, arg GetDocumentVersionDataParams) ([]byte, error) {
row := q.db.QueryRow(ctx, getDocumentVersionData, arg.UUID, arg.Version)
var document_data []byte
err := row.Scan(&document_data)
return document_data, err
}
const getDocumentVersionForArchiving = `-- name: GetDocumentVersionForArchiving :one
SELECT
v.uuid, v.version, v.created, v.creator_uri, v.meta, v.document_data,
p.signature AS parent_signature
FROM document_version AS v
LEFT JOIN document_version AS p
ON p.uuid = v.uuid AND p.version = v.version-1
WHERE v.archived = false
AND (v.version = 1 OR p.archived = true)
ORDER BY v.created
FOR UPDATE OF v SKIP LOCKED
LIMIT 1
`
type GetDocumentVersionForArchivingRow struct {
UUID uuid.UUID
Version int64
Created pgtype.Timestamptz
CreatorUri string
Meta []byte
DocumentData []byte
ParentSignature pgtype.Text
}
func (q *Queries) GetDocumentVersionForArchiving(ctx context.Context) (GetDocumentVersionForArchivingRow, error) {
row := q.db.QueryRow(ctx, getDocumentVersionForArchiving)
var i GetDocumentVersionForArchivingRow
err := row.Scan(
&i.UUID,
&i.Version,
&i.Created,
&i.CreatorUri,
&i.Meta,
&i.DocumentData,
&i.ParentSignature,
)
return i, err
}
const getDueReport = `-- name: GetDueReport :one
SELECT name, enabled, next_execution, spec
FROM report
WHERE enabled AND next_execution < now()
FOR UPDATE SKIP LOCKED
LIMIT 1
`
func (q *Queries) GetDueReport(ctx context.Context) (Report, error) {
row := q.db.QueryRow(ctx, getDueReport)
var i Report
err := row.Scan(
&i.Name,
&i.Enabled,
&i.NextExecution,
&i.Spec,
)
return i, err
}
const getEventlog = `-- name: GetEventlog :many
SELECT id, event, uuid, timestamp, type, version, status, status_id, acl, updater,
language, old_language, main_doc
FROM eventlog
WHERE id > $1
ORDER BY id ASC
LIMIT $2
`
type GetEventlogParams struct {
After int64
RowLimit int32
}
type GetEventlogRow struct {
ID int64
Event string
UUID uuid.UUID
Timestamp pgtype.Timestamptz
Type pgtype.Text
Version pgtype.Int8
Status pgtype.Text
StatusID pgtype.Int8
Acl []byte
Updater pgtype.Text
Language pgtype.Text
OldLanguage pgtype.Text
MainDoc pgtype.UUID
}
func (q *Queries) GetEventlog(ctx context.Context, arg GetEventlogParams) ([]GetEventlogRow, error) {
rows, err := q.db.Query(ctx, getEventlog, arg.After, arg.RowLimit)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetEventlogRow
for rows.Next() {
var i GetEventlogRow
if err := rows.Scan(
&i.ID,
&i.Event,
&i.UUID,
&i.Timestamp,
&i.Type,
&i.Version,
&i.Status,
&i.StatusID,
&i.Acl,
&i.Updater,
&i.Language,
&i.OldLanguage,
&i.MainDoc,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getEventsinkPosition = `-- name: GetEventsinkPosition :one
SELECT position FROM eventsink WHERE name = $1
`
func (q *Queries) GetEventsinkPosition(ctx context.Context, name string) (int64, error) {
row := q.db.QueryRow(ctx, getEventsinkPosition, name)
var position int64
err := row.Scan(&position)
return position, err
}
const getExpiredDocumentLocks = `-- name: GetExpiredDocumentLocks :many
SELECT d.uuid, l.expires AS lock_expires, l.app
FROM document_lock AS l
INNER JOIN document AS d ON d.uuid = l.uuid
WHERE l.expires < $1
FOR UPDATE OF d SKIP LOCKED
`
type GetExpiredDocumentLocksRow struct {
UUID uuid.UUID
LockExpires pgtype.Timestamptz
App pgtype.Text
}
func (q *Queries) GetExpiredDocumentLocks(ctx context.Context, cutoff pgtype.Timestamptz) ([]GetExpiredDocumentLocksRow, error) {
rows, err := q.db.Query(ctx, getExpiredDocumentLocks, cutoff)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetExpiredDocumentLocksRow
for rows.Next() {
var i GetExpiredDocumentLocksRow
if err := rows.Scan(&i.UUID, &i.LockExpires, &i.App); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getFullDocumentHeads = `-- name: GetFullDocumentHeads :many
SELECT s.uuid, s.name, s.id, s.version, s.created, s.creator_uri, s.meta,
s.archived, s.signature, s.meta_doc_version
FROM status_heads AS h
INNER JOIN document_status AS s ON
s.uuid = h.uuid AND s.name = h.name AND s.id = h.current_id
WHERE h.uuid = $1
`
func (q *Queries) GetFullDocumentHeads(ctx context.Context, argUuid uuid.UUID) ([]DocumentStatus, error) {
rows, err := q.db.Query(ctx, getFullDocumentHeads, argUuid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []DocumentStatus
for rows.Next() {
var i DocumentStatus
if err := rows.Scan(
&i.UUID,
&i.Name,
&i.ID,
&i.Version,
&i.Created,
&i.CreatorUri,
&i.Meta,
&i.Archived,
&i.Signature,
&i.MetaDocVersion,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {