-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathsatellite_groups.sql.go
More file actions
117 lines (102 loc) · 2.86 KB
/
satellite_groups.sql.go
File metadata and controls
117 lines (102 loc) · 2.86 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
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: satellite_groups.sql
package database
import (
"context"
)
const addSatelliteToGroup = `-- name: AddSatelliteToGroup :exec
INSERT INTO satellite_groups (satellite_id, group_id)
VALUES ($1, $2)
ON CONFLICT DO NOTHING
`
type AddSatelliteToGroupParams struct {
SatelliteID int32
GroupID int32
}
func (q *Queries) AddSatelliteToGroup(ctx context.Context, arg AddSatelliteToGroupParams) error {
_, err := q.db.ExecContext(ctx, addSatelliteToGroup, arg.SatelliteID, arg.GroupID)
return err
}
const checkSatelliteInGroup = `-- name: CheckSatelliteInGroup :one
SELECT EXISTS (
SELECT 1
FROM satellite_groups
WHERE satellite_id = $1 AND group_id = $2
)
`
type CheckSatelliteInGroupParams struct {
SatelliteID int32
GroupID int32
}
func (q *Queries) CheckSatelliteInGroup(ctx context.Context, arg CheckSatelliteInGroupParams) (bool, error) {
row := q.db.QueryRowContext(ctx, checkSatelliteInGroup, arg.SatelliteID, arg.GroupID)
var exists bool
err := row.Scan(&exists)
return exists, err
}
const groupSatelliteList = `-- name: GroupSatelliteList :many
SELECT satellite_id, group_id FROM satellite_groups
WHERE group_id = $1
`
func (q *Queries) GroupSatelliteList(ctx context.Context, groupID int32) ([]SatelliteGroup, error) {
rows, err := q.db.QueryContext(ctx, groupSatelliteList, groupID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SatelliteGroup
for rows.Next() {
var i SatelliteGroup
if err := rows.Scan(&i.SatelliteID, &i.GroupID); 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 removeSatelliteFromGroup = `-- name: RemoveSatelliteFromGroup :exec
DELETE FROM satellite_groups
WHERE satellite_id = $1 AND group_id = $2
`
type RemoveSatelliteFromGroupParams struct {
SatelliteID int32
GroupID int32
}
func (q *Queries) RemoveSatelliteFromGroup(ctx context.Context, arg RemoveSatelliteFromGroupParams) error {
_, err := q.db.ExecContext(ctx, removeSatelliteFromGroup, arg.SatelliteID, arg.GroupID)
return err
}
const satelliteGroupList = `-- name: SatelliteGroupList :many
SELECT satellite_id, group_id FROM satellite_groups
WHERE satellite_id = $1
`
func (q *Queries) SatelliteGroupList(ctx context.Context, satelliteID int32) ([]SatelliteGroup, error) {
rows, err := q.db.QueryContext(ctx, satelliteGroupList, satelliteID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SatelliteGroup
for rows.Next() {
var i SatelliteGroup
if err := rows.Scan(&i.SatelliteID, &i.GroupID); 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
}