stillbox/pkg/database/talkgroups.sql.go
Daniel Ponte d95cda6b44 Mutation to get all tags (#76)
Reviewed-on: #76
Co-authored-by: Daniel Ponte <amigan@gmail.com>
Co-committed-by: Daniel Ponte <amigan@gmail.com>
2024-12-18 10:51:26 -05:00

790 lines
21 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: talkgroups.sql
package database
import (
"context"
"dynatron.me/x/stillbox/internal/jsontypes"
"dynatron.me/x/stillbox/pkg/alerting/rules"
)
const addLearnedTalkgroup = `-- name: AddLearnedTalkgroup :one
INSERT INTO talkgroups(
system_id,
tgid,
learned,
name,
alpha_tag,
tg_group
) VALUES (
$1,
$2,
TRUE,
$3,
$4,
$5
) RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored
`
type AddLearnedTalkgroupParams struct {
SystemID int32 `json:"system_id"`
TGID int32 `json:"tgid"`
Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"`
TGGroup *string `json:"tg_group"`
}
func (q *Queries) AddLearnedTalkgroup(ctx context.Context, arg AddLearnedTalkgroupParams) (Talkgroup, error) {
row := q.db.QueryRow(ctx, addLearnedTalkgroup,
arg.SystemID,
arg.TGID,
arg.Name,
arg.AlphaTag,
arg.TGGroup,
)
var i Talkgroup
err := row.Scan(
&i.ID,
&i.SystemID,
&i.TGID,
&i.Name,
&i.AlphaTag,
&i.TGGroup,
&i.Frequency,
&i.Metadata,
&i.Tags,
&i.Alert,
&i.AlertConfig,
&i.Weight,
&i.Learned,
&i.Ignored,
)
return i, err
}
const createSystem = `-- name: CreateSystem :exec
INSERT INTO systems(id, name) VALUES($1, $2)
`
func (q *Queries) CreateSystem(ctx context.Context, iD int, name string) error {
_, err := q.db.Exec(ctx, createSystem, iD, name)
return err
}
const deleteSystem = `-- name: DeleteSystem :exec
DELETE FROM systems WHERE id = $1
`
func (q *Queries) DeleteSystem(ctx context.Context, id int) error {
_, err := q.db.Exec(ctx, deleteSystem, id)
return err
}
const deleteTalkgroup = `-- name: DeleteTalkgroup :exec
DELETE FROM talkgroups WHERE system_id = $1 AND tgid = $2
`
func (q *Queries) DeleteTalkgroup(ctx context.Context, systemID int32, tGID int32) error {
_, err := q.db.Exec(ctx, deleteTalkgroup, systemID, tGID)
return err
}
const getAllTalkgroupTags = `-- name: GetAllTalkgroupTags :many
SELECT UNNEST(tgs.tags)::TEXT tag FROM talkgroups tgs GROUP BY tag ORDER BY COUNT(*) DESC
`
func (q *Queries) GetAllTalkgroupTags(ctx context.Context) ([]string, error) {
rows, err := q.db.Query(ctx, getAllTalkgroupTags)
if err != nil {
return nil, err
}
defer rows.Close()
var items []string
for rows.Next() {
var tag string
if err := rows.Scan(&tag); err != nil {
return nil, err
}
items = append(items, tag)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getSystemName = `-- name: GetSystemName :one
SELECT name FROM systems WHERE id = $1
`
func (q *Queries) GetSystemName(ctx context.Context, systemID int) (string, error) {
row := q.db.QueryRow(ctx, getSystemName, systemID)
var name string
err := row.Scan(&name)
return name, err
}
const getTalkgroup = `-- name: GetTalkgroup :one
SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups
WHERE (system_id, tgid) = ($1, $2)
`
type GetTalkgroupRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
}
func (q *Queries) GetTalkgroup(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupRow, error) {
row := q.db.QueryRow(ctx, getTalkgroup, systemID, tGID)
var i GetTalkgroupRow
err := row.Scan(
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
)
return i, err
}
const getTalkgroupIDsByTags = `-- name: GetTalkgroupIDsByTags :many
SELECT system_id, tgid FROM talkgroups
WHERE (tags @> ARRAY[$1])
AND (tags && ARRAY[$2])
AND NOT (tags @> ARRAY[$3])
`
type GetTalkgroupIDsByTagsRow struct {
SystemID int32 `json:"system_id"`
TGID int32 `json:"tgid"`
}
func (q *Queries) GetTalkgroupIDsByTags(ctx context.Context, anyTags []string, allTags []string, notTags []string) ([]GetTalkgroupIDsByTagsRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupIDsByTags, anyTags, allTags, notTags)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupIDsByTagsRow
for rows.Next() {
var i GetTalkgroupIDsByTagsRow
if err := rows.Scan(&i.SystemID, &i.TGID); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTalkgroupTags = `-- name: GetTalkgroupTags :one
SELECT tags FROM talkgroups
WHERE system_id = $1 AND tgid = $2
`
func (q *Queries) GetTalkgroupTags(ctx context.Context, systemID int32, tGID int32) ([]string, error) {
row := q.db.QueryRow(ctx, getTalkgroupTags, systemID, tGID)
var tags []string
err := row.Scan(&tags)
return tags, err
}
const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one
SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
WHERE (tg.system_id, tg.tgid) = ($1, $2)
`
type GetTalkgroupWithLearnedRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
}
func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupWithLearnedRow, error) {
row := q.db.QueryRow(ctx, getTalkgroupWithLearned, systemID, tGID)
var i GetTalkgroupWithLearnedRow
err := row.Scan(
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
&i.System.ID,
&i.System.Name,
)
return i, err
}
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups
WHERE tags && ARRAY[$1]
`
type GetTalkgroupsWithAllTagsRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
}
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.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
); 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 talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups
WHERE tags @> ARRAY[$1]
`
type GetTalkgroupsWithAnyTagsRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
}
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.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTalkgroupsWithLearned = `-- name: GetTalkgroupsWithLearned :many
SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
WHERE ignored IS NOT TRUE
`
type GetTalkgroupsWithLearnedRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
}
func (q *Queries) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroupsWithLearnedRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithLearned)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupsWithLearnedRow
for rows.Next() {
var i GetTalkgroupsWithLearnedRow
if err := rows.Scan(
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
&i.System.ID,
&i.System.Name,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTalkgroupsWithLearnedBySystem = `-- name: GetTalkgroupsWithLearnedBySystem :many
SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
WHERE tg.system_id = $1
`
type GetTalkgroupsWithLearnedBySystemRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
}
func (q *Queries) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]GetTalkgroupsWithLearnedBySystemRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithLearnedBySystem, system)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupsWithLearnedBySystemRow
for rows.Next() {
var i GetTalkgroupsWithLearnedBySystemRow
if err := rows.Scan(
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
&i.System.ID,
&i.System.Name,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTalkgroupsWithLearnedBySystemCount = `-- name: GetTalkgroupsWithLearnedBySystemCount :one
SELECT COUNT(*) FROM talkgroups tg
WHERE tg.system_id = $1 AND
(CASE WHEN $2::TEXT IS NOT NULL THEN (
tg.tg_group ILIKE '%' || $2 || '%' OR
tg.name ILIKE '%' || $2 || '%' OR
tg.alpha_tag ILIKE '%' || $2 || '%' OR
tg.tags @> ARRAY[LOWER($2)]
) ELSE TRUE END)
`
func (q *Queries) GetTalkgroupsWithLearnedBySystemCount(ctx context.Context, system int32, filter *string) (int64, error) {
row := q.db.QueryRow(ctx, getTalkgroupsWithLearnedBySystemCount, system, filter)
var count int64
err := row.Scan(&count)
return count, err
}
const getTalkgroupsWithLearnedBySystemP = `-- name: GetTalkgroupsWithLearnedBySystemP :many
SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
WHERE tg.system_id = $1 AND
(CASE WHEN $2::TEXT IS NOT NULL THEN (
tg.tg_group ILIKE '%' || $2 || '%' OR
tg.name ILIKE '%' || $2 || '%' OR
tg.alpha_tag ILIKE '%' || $2 || '%' OR
tg.tags @> ARRAY[LOWER($2)]
) ELSE TRUE END)
ORDER BY
CASE WHEN $3::TEXT = 'tgid_asc' THEN (tg.system_id, tg.tgid) END ASC,
CASE WHEN $3 = 'tgid_desc' THEN (tg.system_id, tg.tgid) END DESC,
CASE WHEN $3 = 'group_asc' THEN tg.tg_group END ASC,
CASE WHEN $3 = 'group_desc' THEN tg.tg_group END DESC,
CASE WHEN $3 = 'id_asc' THEN tg.id END ASC,
CASE WHEN $3 = 'id_desc' THEN tg.id END DESC,
CASE WHEN $3 = 'name_asc' THEN tg.name END ASC,
CASE WHEN $3 = 'name_desc' THEN tg.name END DESC,
CASE WHEN $3 = 'alpha_asc' THEN tg.alpha_tag END ASC,
CASE WHEN $3 = 'alpha_desc' THEN tg.alpha_tag END DESC
OFFSET $4 ROWS
FETCH NEXT $5 ROWS ONLY
`
type GetTalkgroupsWithLearnedBySystemPParams struct {
System int32 `json:"system"`
Filter *string `json:"filter"`
OrderBy string `json:"order_by"`
Offset int32 `json:"offset"`
PerPage int32 `json:"per_page"`
}
type GetTalkgroupsWithLearnedBySystemPRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
}
func (q *Queries) GetTalkgroupsWithLearnedBySystemP(ctx context.Context, arg GetTalkgroupsWithLearnedBySystemPParams) ([]GetTalkgroupsWithLearnedBySystemPRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithLearnedBySystemP,
arg.System,
arg.Filter,
arg.OrderBy,
arg.Offset,
arg.PerPage,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupsWithLearnedBySystemPRow
for rows.Next() {
var i GetTalkgroupsWithLearnedBySystemPRow
if err := rows.Scan(
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
&i.System.ID,
&i.System.Name,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTalkgroupsWithLearnedCount = `-- name: GetTalkgroupsWithLearnedCount :one
SELECT COUNT(*) FROM talkgroups tg
WHERE ignored IS NOT TRUE AND
(CASE WHEN $1::TEXT IS NOT NULL THEN (
tg.tg_group ILIKE '%' || $1 || '%' OR
tg.name ILIKE '%' || $1 || '%' OR
tg.alpha_tag ILIKE '%' || $1 || '%' OR
tg.tags @> ARRAY[LOWER($1)]
) ELSE TRUE END)
`
func (q *Queries) GetTalkgroupsWithLearnedCount(ctx context.Context, filter *string) (int64, error) {
row := q.db.QueryRow(ctx, getTalkgroupsWithLearnedCount, filter)
var count int64
err := row.Scan(&count)
return count, err
}
const getTalkgroupsWithLearnedP = `-- name: GetTalkgroupsWithLearnedP :many
SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
WHERE ignored IS NOT TRUE AND
(CASE WHEN $1::TEXT IS NOT NULL THEN (
tg.tg_group ILIKE '%' || $1 || '%' OR
tg.name ILIKE '%' || $1 || '%' OR
tg.alpha_tag ILIKE '%' || $1 || '%' OR
tg.tags @> ARRAY[LOWER($1)]
) ELSE TRUE END)
ORDER BY
CASE WHEN $2::TEXT = 'tgid_asc' THEN (tg.system_id, tg.tgid) END ASC,
CASE WHEN $2 = 'tgid_desc' THEN (tg.system_id, tg.tgid) END DESC,
CASE WHEN $2 = 'group_asc' THEN tg.tg_group END ASC,
CASE WHEN $2 = 'group_desc' THEN tg.tg_group END DESC,
CASE WHEN $2 = 'id_asc' THEN tg.id END ASC,
CASE WHEN $2 = 'id_desc' THEN tg.id END DESC,
CASE WHEN $2 = 'name_asc' THEN tg.name END ASC,
CASE WHEN $2 = 'name_desc' THEN tg.name END DESC,
CASE WHEN $2 = 'alpha_asc' THEN tg.alpha_tag END ASC,
CASE WHEN $2 = 'alpha_desc' THEN tg.alpha_tag END DESC
OFFSET $3 ROWS
FETCH NEXT $4 ROWS ONLY
`
type GetTalkgroupsWithLearnedPParams struct {
Filter *string `json:"filter"`
OrderBy string `json:"order_by"`
Offset int32 `json:"offset"`
PerPage int32 `json:"per_page"`
}
type GetTalkgroupsWithLearnedPRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
}
func (q *Queries) GetTalkgroupsWithLearnedP(ctx context.Context, arg GetTalkgroupsWithLearnedPParams) ([]GetTalkgroupsWithLearnedPRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithLearnedP,
arg.Filter,
arg.OrderBy,
arg.Offset,
arg.PerPage,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupsWithLearnedPRow
for rows.Next() {
var i GetTalkgroupsWithLearnedPRow
if err := rows.Scan(
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
&i.Talkgroup.TGID,
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
&i.Talkgroup.TGGroup,
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,
&i.System.ID,
&i.System.Name,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const restoreTalkgroupVersion = `-- name: RestoreTalkgroupVersion :one
INSERT INTO talkgroups(
system_id,
tgid,
name,
alpha_tag,
tg_group,
frequency,
metadata,
tags,
alert,
alert_config,
weight,
learned,
ignored
)
SELECT
system_id,
tgid,
name,
alpha_tag,
tg_group,
frequency,
metadata,
tags,
alert,
alert_config,
weight,
learned,
ignored
FROM talkgroup_versions tgv ON CONFLICT (system_id, tgid) DO UPDATE SET
name = excluded.name,
alpha_tag = excluded.alpha_tag,
tg_group = excluded.tg_group,
metadata = excluded.metadata,
tags = excluded.tags,
alert = excluded.alert,
alert_config = excluded.alert_config,
weight = excluded.weight,
learned = excluded.learner,
ignored = excluded.ignored
WHERE tgv.id = ANY($1)
RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored
`
func (q *Queries) RestoreTalkgroupVersion(ctx context.Context, versionIds int) (Talkgroup, error) {
row := q.db.QueryRow(ctx, restoreTalkgroupVersion, versionIds)
var i Talkgroup
err := row.Scan(
&i.ID,
&i.SystemID,
&i.TGID,
&i.Name,
&i.AlphaTag,
&i.TGGroup,
&i.Frequency,
&i.Metadata,
&i.Tags,
&i.Alert,
&i.AlertConfig,
&i.Weight,
&i.Learned,
&i.Ignored,
)
return i, err
}
const setTalkgroupTags = `-- name: SetTalkgroupTags :exec
UPDATE talkgroups SET tags = $1
WHERE system_id = $2 AND tgid = $3
`
func (q *Queries) SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tGID int32) error {
_, err := q.db.Exec(ctx, setTalkgroupTags, tags, systemID, tGID)
return err
}
const storeDeletedTGVersion = `-- name: StoreDeletedTGVersion :exec
INSERT INTO talkgroup_versions(
system_id,
tgid,
time,
created_by,
deleted
) VALUES($1, $2, NOW(), $3, TRUE)
`
func (q *Queries) StoreDeletedTGVersion(ctx context.Context, systemID *int32, tGID *int32, submitter *int32) error {
_, err := q.db.Exec(ctx, storeDeletedTGVersion, systemID, tGID, submitter)
return err
}
const updateTalkgroup = `-- name: UpdateTalkgroup :one
UPDATE talkgroups
SET
name = COALESCE($1, name),
alpha_tag = COALESCE($2, alpha_tag),
tg_group = COALESCE($3, tg_group),
frequency = COALESCE($4, frequency),
metadata = COALESCE($5, metadata),
tags = COALESCE($6, tags),
alert = COALESCE($7, alert),
alert_config = COALESCE($8, alert_config),
weight = COALESCE($9, weight),
learned = COALESCE($10, learned)
WHERE id = $11 OR (system_id = $12 AND tgid = $13)
RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored
`
type UpdateTalkgroupParams struct {
Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"`
TGGroup *string `json:"tg_group"`
Frequency *int32 `json:"frequency"`
Metadata jsontypes.Metadata `json:"metadata"`
Tags []string `json:"tags"`
Alert *bool `json:"alert"`
AlertConfig rules.AlertRules `json:"alert_config"`
Weight *float32 `json:"weight"`
Learned *bool `json:"learned"`
ID *int32 `json:"id"`
SystemID *int32 `json:"system_id"`
TGID *int32 `json:"tgid"`
}
func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams) (Talkgroup, error) {
row := q.db.QueryRow(ctx, updateTalkgroup,
arg.Name,
arg.AlphaTag,
arg.TGGroup,
arg.Frequency,
arg.Metadata,
arg.Tags,
arg.Alert,
arg.AlertConfig,
arg.Weight,
arg.Learned,
arg.ID,
arg.SystemID,
arg.TGID,
)
var i Talkgroup
err := row.Scan(
&i.ID,
&i.SystemID,
&i.TGID,
&i.Name,
&i.AlphaTag,
&i.TGGroup,
&i.Frequency,
&i.Metadata,
&i.Tags,
&i.Alert,
&i.AlertConfig,
&i.Weight,
&i.Learned,
&i.Ignored,
)
return i, err
}