2024-07-17 19:30:16 -04:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
|
|
|
// sqlc v1.26.0
|
|
|
|
// source: talkgroups.sql
|
|
|
|
|
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
const getTalkgroupTags = `-- name: GetTalkgroupTags :one
|
|
|
|
SELECT tags FROM talkgroups_tags
|
|
|
|
WHERE talkgroup_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetTalkgroupTags(ctx context.Context, talkgroupID int32) ([]string, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getTalkgroupTags, talkgroupID)
|
|
|
|
var tags []string
|
|
|
|
err := row.Scan(&tags)
|
|
|
|
return tags, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
|
2024-07-17 19:40:21 -04:00
|
|
|
SELECT talkgroup_id FROM talkgroups_tags
|
2024-07-17 19:30:16 -04:00
|
|
|
WHERE tags && ARRAY[$1]
|
|
|
|
`
|
|
|
|
|
2024-07-17 19:40:21 -04:00
|
|
|
func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]int32, error) {
|
2024-07-17 19:30:16 -04:00
|
|
|
rows, err := q.db.Query(ctx, getTalkgroupsWithAllTags, tags)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-07-17 19:40:21 -04:00
|
|
|
var items []int32
|
2024-07-17 19:30:16 -04:00
|
|
|
for rows.Next() {
|
2024-07-17 19:40:21 -04:00
|
|
|
var talkgroup_id int32
|
|
|
|
if err := rows.Scan(&talkgroup_id); err != nil {
|
2024-07-17 19:30:16 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-07-17 19:40:21 -04:00
|
|
|
items = append(items, talkgroup_id)
|
2024-07-17 19:30:16 -04:00
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
|
2024-07-17 19:40:21 -04:00
|
|
|
SELECT talkgroup_id FROM talkgroups_tags
|
2024-07-17 19:30:16 -04:00
|
|
|
WHERE tags @> ARRAY[$1]
|
|
|
|
`
|
|
|
|
|
2024-07-17 19:40:21 -04:00
|
|
|
func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]int32, error) {
|
2024-07-17 19:30:16 -04:00
|
|
|
rows, err := q.db.Query(ctx, getTalkgroupsWithAnyTags, tags)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
2024-07-17 19:40:21 -04:00
|
|
|
var items []int32
|
2024-07-17 19:30:16 -04:00
|
|
|
for rows.Next() {
|
2024-07-17 19:40:21 -04:00
|
|
|
var talkgroup_id int32
|
|
|
|
if err := rows.Scan(&talkgroup_id); err != nil {
|
2024-07-17 19:30:16 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-07-17 19:40:21 -04:00
|
|
|
items = append(items, talkgroup_id)
|
2024-07-17 19:30:16 -04:00
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const setTalkgroupTags = `-- name: SetTalkgroupTags :exec
|
|
|
|
INSERT INTO talkgroups_tags(talkgroup_id, tags) VALUES($1, $2)
|
2024-07-17 19:33:09 -04:00
|
|
|
ON CONFLICT (talkgroup_id) DO UPDATE SET tags = $2
|
2024-07-17 19:30:16 -04:00
|
|
|
`
|
|
|
|
|
|
|
|
type SetTalkgroupTagsParams struct {
|
|
|
|
TalkgroupID int32
|
|
|
|
Tags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) SetTalkgroupTags(ctx context.Context, arg SetTalkgroupTagsParams) error {
|
|
|
|
_, err := q.db.Exec(ctx, setTalkgroupTags, arg.TalkgroupID, arg.Tags)
|
|
|
|
return err
|
|
|
|
}
|