stillbox/pkg/gordio/database/talkgroups.sql.go
2024-07-25 09:37:27 -04:00

92 lines
2.4 KiB
Go

// 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 int) ([]string, error) {
row := q.db.QueryRow(ctx, getTalkgroupTags, talkgroupID)
var tags []string
err := row.Scan(&tags)
return tags, err
}
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
SELECT system_id, talkgroup_id FROM talkgroups_tags
WHERE tags && ARRAY[$1]
`
type GetTalkgroupsWithAllTagsRow struct {
SystemID int `json:"system_id"`
TalkgroupID int `json:"talkgroup_id"`
}
func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAllTagsRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithAllTags, tags)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupsWithAllTagsRow
for rows.Next() {
var i GetTalkgroupsWithAllTagsRow
if err := rows.Scan(&i.SystemID, &i.TalkgroupID); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
SELECT system_id, talkgroup_id FROM talkgroups_tags
WHERE tags @> ARRAY[$1]
`
type GetTalkgroupsWithAnyTagsRow struct {
SystemID int `json:"system_id"`
TalkgroupID int `json:"talkgroup_id"`
}
func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAnyTagsRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithAnyTags, tags)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupsWithAnyTagsRow
for rows.Next() {
var i GetTalkgroupsWithAnyTagsRow
if err := rows.Scan(&i.SystemID, &i.TalkgroupID); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const setTalkgroupTags = `-- name: SetTalkgroupTags :exec
INSERT INTO talkgroups_tags(system_id, talkgroup_id, tags) VALUES($1, $2, $3)
ON CONFLICT (system_id, talkgroup_id) DO UPDATE SET tags = $3
`
func (q *Queries) SetTalkgroupTags(ctx context.Context, systemID int, talkgroupID int, tags []string) error {
_, err := q.db.Exec(ctx, setTalkgroupTags, systemID, talkgroupID, tags)
return err
}