-
Notifications
You must be signed in to change notification settings - Fork 2
/
third_party_mappings.sql.go
98 lines (87 loc) · 2.4 KB
/
third_party_mappings.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
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.25.0
// source: third_party_mappings.sql
package gensql
import (
"context"
"github.com/google/uuid"
"github.com/lib/pq"
)
const getDatasetMappings = `-- name: GetDatasetMappings :one
SELECT services, dataset_id
FROM third_party_mappings
WHERE "dataset_id" = $1
`
func (q *Queries) GetDatasetMappings(ctx context.Context, datasetID uuid.UUID) (ThirdPartyMapping, error) {
row := q.db.QueryRowContext(ctx, getDatasetMappings, datasetID)
var i ThirdPartyMapping
err := row.Scan(pq.Array(&i.Services), &i.DatasetID)
return i, err
}
const getDatasetsByMapping = `-- name: GetDatasetsByMapping :many
SELECT datasets.id, datasets.name, datasets.description, datasets.pii, datasets.created, datasets.last_modified, datasets.type, datasets.tsv_document, datasets.slug, datasets.repo, datasets.keywords, datasets.dataproduct_id, datasets.anonymisation_description, datasets.target_user FROM third_party_mappings
INNER JOIN datasets ON datasets.id = third_party_mappings.dataset_id
WHERE $1::TEXT = ANY("services")
LIMIT $3 OFFSET $2
`
type GetDatasetsByMappingParams struct {
Service string
Offs int32
Lim int32
}
func (q *Queries) GetDatasetsByMapping(ctx context.Context, arg GetDatasetsByMappingParams) ([]Dataset, error) {
rows, err := q.db.QueryContext(ctx, getDatasetsByMapping, arg.Service, arg.Offs, arg.Lim)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Dataset{}
for rows.Next() {
var i Dataset
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Description,
&i.Pii,
&i.Created,
&i.LastModified,
&i.Type,
&i.TsvDocument,
&i.Slug,
&i.Repo,
pq.Array(&i.Keywords),
&i.DataproductID,
&i.AnonymisationDescription,
&i.TargetUser,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const mapDataset = `-- name: MapDataset :exec
INSERT INTO third_party_mappings (
"dataset_id",
"services"
) VALUES (
$1,
$2
) ON CONFLICT ("dataset_id") DO UPDATE SET
"services" = EXCLUDED.services
`
type MapDatasetParams struct {
DatasetID uuid.UUID
Services []string
}
func (q *Queries) MapDataset(ctx context.Context, arg MapDatasetParams) error {
_, err := q.db.ExecContext(ctx, mapDataset, arg.DatasetID, pq.Array(arg.Services))
return err
}