stillbox/pkg/database/talkgroups.sql.go

478 lines
13 KiB
Go
Raw Normal View History

2024-07-17 19:30:16 -04:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
2024-11-15 11:34:54 -05:00
// sqlc v1.27.0
2024-07-17 19:30:16 -04:00
// source: talkgroups.sql
package database
import (
"context"
2024-11-13 09:24:11 -05:00
"dynatron.me/x/stillbox/internal/jsontypes"
"dynatron.me/x/stillbox/pkg/alerting/rules"
2024-07-17 19:30:16 -04:00
)
2024-11-17 21:46:10 -05:00
const addLearnedTalkgroup = `-- name: AddLearnedTalkgroup :one
INSERT INTO talkgroups_learned(
system_id,
tgid,
name,
alpha_tag,
tg_group
) VALUES (
$1,
$2,
$3,
$4,
$5
) RETURNING id
`
type AddLearnedTalkgroupParams struct {
SystemID int `json:"system_id"`
TGID int `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) (int, error) {
row := q.db.QueryRow(ctx, addLearnedTalkgroup,
arg.SystemID,
arg.TGID,
arg.Name,
arg.AlphaTag,
arg.TGGroup,
)
var id int
err := row.Scan(&id)
return id, err
}
const addTalkgroupWithLearnedFlag = `-- name: AddTalkgroupWithLearnedFlag :exec
INSERT INTO talkgroups (
system_id,
tgid,
learned
) VALUES(
$1,
$2,
2024-11-20 07:26:59 -05:00
TRUE
2024-11-17 21:46:10 -05:00
)
`
func (q *Queries) AddTalkgroupWithLearnedFlag(ctx context.Context, systemID int32, tGID int32) error {
_, err := q.db.Exec(ctx, addTalkgroupWithLearnedFlag, systemID, tGID)
return err
}
2024-10-31 00:10:53 -04:00
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
}
2024-08-16 14:54:50 -04:00
const getTalkgroup = `-- name: GetTalkgroup :one
2024-11-17 21:46:10 -05:00
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 FROM talkgroups
2024-11-14 08:37:19 -05:00
WHERE (system_id, tgid) = ($1, $2)
2024-08-16 14:54:50 -04:00
`
2024-11-03 08:44:34 -05:00
type GetTalkgroupRow struct {
Talkgroup Talkgroup `json:"talkgroup"`
}
2024-11-17 21:46:10 -05:00
func (q *Queries) GetTalkgroup(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupRow, error) {
row := q.db.QueryRow(ctx, getTalkgroup, systemID, tGID)
2024-11-03 08:44:34 -05:00
var i GetTalkgroupRow
2024-08-16 14:54:50 -04:00
err := row.Scan(
2024-11-03 08:44:34 -05:00
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
2024-11-15 11:34:54 -05:00
&i.Talkgroup.TGID,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.TGGroup,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.Learned,
2024-08-16 14:54:50 -04:00
)
return i, err
}
2024-08-06 11:19:30 -04:00
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"`
2024-11-15 11:34:54 -05:00
TGID int32 `json:"tgid"`
2024-08-06 11:19:30 -04:00
}
2024-11-15 11:34:54 -05:00
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)
2024-08-06 11:19:30 -04:00
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetTalkgroupIDsByTagsRow
for rows.Next() {
var i GetTalkgroupIDsByTagsRow
2024-11-15 11:34:54 -05:00
if err := rows.Scan(&i.SystemID, &i.TGID); err != nil {
2024-08-06 11:19:30 -04:00
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
2024-07-17 19:30:16 -04:00
const getTalkgroupTags = `-- name: GetTalkgroupTags :one
2024-07-28 23:07:04 -04:00
SELECT tags FROM talkgroups
2024-11-15 10:37:58 -05:00
WHERE system_id = $1 AND tgid = $2
2024-07-17 19:30:16 -04:00
`
2024-11-17 21:46:10 -05:00
func (q *Queries) GetTalkgroupTags(ctx context.Context, systemID int32, tGID int32) ([]string, error) {
row := q.db.QueryRow(ctx, getTalkgroupTags, systemID, tGID)
2024-07-17 19:30:16 -04:00
var tags []string
err := row.Scan(&tags)
return tags, err
}
2024-08-16 16:47:39 -04:00
const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one
SELECT
2024-11-17 21:46:10 -05:00
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, sys.id, sys.name
2024-08-16 16:47:39 -04:00
FROM talkgroups tg
2024-08-20 08:17:02 -04:00
JOIN systems sys ON tg.system_id = sys.id
2024-11-17 21:46:10 -05:00
WHERE (tg.system_id, tg.tgid) = ($1, $2) AND tg.learned IS NOT TRUE
2024-08-16 16:47:39 -04:00
UNION
SELECT
2024-11-15 23:25:57 -05:00
tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name,
2024-11-17 21:46:10 -05:00
tgl.alpha_tag, tgl.tg_group, NULL::INTEGER, NULL::JSONB,
CASE WHEN tgl.tg_group IS NULL THEN NULL ELSE ARRAY[tgl.tg_group] END,
2024-11-19 10:00:35 -05:00
NOT tgl.ignored, NULL::JSONB, 1.0, TRUE learned, sys.id, sys.name
2024-08-16 16:47:39 -04:00
FROM talkgroups_learned tgl
2024-08-20 08:17:02 -04:00
JOIN systems sys ON tgl.system_id = sys.id
WHERE tgl.system_id = $1 AND tgl.tgid = $2 AND ignored IS NOT TRUE
2024-08-16 16:47:39 -04:00
`
type GetTalkgroupWithLearnedRow struct {
2024-11-03 08:44:34 -05:00
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
2024-08-16 16:47:39 -04:00
}
2024-11-15 11:34:54 -05:00
func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int32, tGID int32) (GetTalkgroupWithLearnedRow, error) {
row := q.db.QueryRow(ctx, getTalkgroupWithLearned, systemID, tGID)
2024-08-16 16:47:39 -04:00
var i GetTalkgroupWithLearnedRow
err := row.Scan(
2024-11-03 08:44:34 -05:00
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
2024-11-15 11:34:54 -05:00
&i.Talkgroup.TGID,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.TGGroup,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.Learned,
2024-11-03 08:44:34 -05:00
&i.System.ID,
&i.System.Name,
2024-08-16 16:47:39 -04:00
)
return i, err
}
2024-11-04 23:41:52 -05:00
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
2024-11-17 21:46:10 -05:00
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 FROM talkgroups
2024-11-04 23:41:52 -05:00
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,
2024-11-15 11:34:54 -05:00
&i.Talkgroup.TGID,
2024-11-04 23:41:52 -05:00
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.TGGroup,
2024-11-04 23:41:52 -05:00
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.Learned,
2024-11-04 23:41:52 -05:00
); 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
2024-11-17 21:46:10 -05:00
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 FROM talkgroups
2024-11-04 23:41:52 -05:00
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,
2024-11-15 11:34:54 -05:00
&i.Talkgroup.TGID,
2024-11-04 23:41:52 -05:00
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.TGGroup,
2024-11-04 23:41:52 -05:00
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.Learned,
2024-11-04 23:41:52 -05:00
); 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
2024-11-17 21:46:10 -05:00
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, sys.id, sys.name
2024-11-04 23:41:52 -05:00
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
2024-11-17 21:46:10 -05:00
WHERE tg.learned IS NOT TRUE
2024-11-04 23:41:52 -05:00
UNION
SELECT
2024-11-15 23:25:57 -05:00
tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name,
2024-11-17 21:46:10 -05:00
tgl.alpha_tag, tgl.tg_group, NULL::INTEGER, NULL::JSONB,
CASE WHEN tgl.tg_group IS NULL THEN NULL ELSE ARRAY[tgl.tg_group] END,
2024-11-19 10:00:35 -05:00
NOT tgl.ignored, NULL::JSONB, 1.0, TRUE learned, sys.id, sys.name
2024-11-04 23:41:52 -05:00
FROM talkgroups_learned tgl
JOIN systems sys ON tgl.system_id = sys.id
WHERE ignored IS NOT TRUE
`
2024-11-04 23:41:52 -05:00
type GetTalkgroupsWithLearnedRow struct {
2024-11-03 08:44:34 -05:00
Talkgroup Talkgroup `json:"talkgroup"`
System System `json:"system"`
}
2024-11-04 23:41:52 -05:00
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()
2024-11-04 23:41:52 -05:00
var items []GetTalkgroupsWithLearnedRow
for rows.Next() {
2024-11-04 23:41:52 -05:00
var i GetTalkgroupsWithLearnedRow
if err := rows.Scan(
2024-11-03 08:44:34 -05:00
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
2024-11-15 11:34:54 -05:00
&i.Talkgroup.TGID,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.TGGroup,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.Learned,
2024-11-03 08:44:34 -05:00
&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
}
2024-11-04 23:41:52 -05:00
const getTalkgroupsWithLearnedBySystem = `-- name: GetTalkgroupsWithLearnedBySystem :many
SELECT
2024-11-17 21:46:10 -05:00
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, sys.id, sys.name
2024-11-04 23:41:52 -05:00
FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id
2024-11-17 21:46:10 -05:00
WHERE tg.system_id = $1 AND tg.learned IS NOT TRUE
2024-11-04 23:41:52 -05:00
UNION
SELECT
2024-11-15 23:25:57 -05:00
tgl.id, tgl.system_id::INT4, tgl.tgid::INT4, tgl.name,
2024-11-17 21:46:10 -05:00
tgl.alpha_tag, tgl.tg_group, NULL::INTEGER, NULL::JSONB,
CASE WHEN tgl.tg_group IS NULL THEN NULL ELSE ARRAY[tgl.tg_group] END,
2024-11-19 10:00:35 -05:00
NOT tgl.ignored, NULL::JSONB, 1.0, TRUE learned, sys.id, sys.name
2024-11-04 23:41:52 -05:00
FROM talkgroups_learned tgl
JOIN systems sys ON tgl.system_id = sys.id
WHERE tgl.system_id = $1 AND ignored IS NOT TRUE
2024-07-17 19:30:16 -04:00
`
2024-11-04 23:41:52 -05:00
type GetTalkgroupsWithLearnedBySystemRow struct {
2024-11-03 08:44:34 -05:00
Talkgroup Talkgroup `json:"talkgroup"`
2024-11-04 23:41:52 -05:00
System System `json:"system"`
2024-11-03 08:44:34 -05:00
}
2024-11-04 23:41:52 -05:00
func (q *Queries) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system int32) ([]GetTalkgroupsWithLearnedBySystemRow, error) {
rows, err := q.db.Query(ctx, getTalkgroupsWithLearnedBySystem, system)
2024-07-17 19:30:16 -04:00
if err != nil {
return nil, err
}
defer rows.Close()
2024-11-04 23:41:52 -05:00
var items []GetTalkgroupsWithLearnedBySystemRow
2024-07-17 19:30:16 -04:00
for rows.Next() {
2024-11-04 23:41:52 -05:00
var i GetTalkgroupsWithLearnedBySystemRow
2024-07-28 23:07:04 -04:00
if err := rows.Scan(
2024-11-03 08:44:34 -05:00
&i.Talkgroup.ID,
&i.Talkgroup.SystemID,
2024-11-15 11:34:54 -05:00
&i.Talkgroup.TGID,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Name,
&i.Talkgroup.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.TGGroup,
2024-11-03 08:44:34 -05:00
&i.Talkgroup.Frequency,
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.Weight,
2024-11-17 21:46:10 -05:00
&i.Talkgroup.Learned,
2024-11-04 23:41:52 -05:00
&i.System.ID,
&i.System.Name,
2024-07-28 23:07:04 -04:00
); err != nil {
2024-07-17 19:30:16 -04:00
return nil, err
}
2024-07-17 19:45:46 -04:00
items = append(items, i)
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
2024-11-15 10:37:58 -05:00
UPDATE talkgroups SET tags = $1
WHERE system_id = $2 AND tgid = $3
2024-07-17 19:30:16 -04:00
`
2024-11-17 21:46:10 -05:00
func (q *Queries) SetTalkgroupTags(ctx context.Context, tags []string, systemID int32, tGID int32) error {
_, err := q.db.Exec(ctx, setTalkgroupTags, tags, systemID, tGID)
2024-07-17 19:30:16 -04:00
return err
}
2024-11-10 10:13:38 -05:00
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),
2024-11-20 07:26:59 -05:00
weight = COALESCE($9, weight),
learned = COALESCE($10, learned)
WHERE id = $11 OR (system_id = $12 AND tgid = $13)
2024-11-17 21:46:10 -05:00
RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned
2024-11-10 10:13:38 -05:00
`
type UpdateTalkgroupParams struct {
2024-11-13 09:24:11 -05:00
Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"`
2024-11-17 21:46:10 -05:00
TGGroup *string `json:"tg_group"`
2024-11-13 09:24:11 -05:00
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"`
2024-11-20 07:26:59 -05:00
Learned *bool `json:"learned"`
2024-11-19 10:00:35 -05:00
ID *int32 `json:"id"`
2024-11-14 08:37:19 -05:00
SystemID *int32 `json:"system_id"`
2024-11-15 11:34:54 -05:00
TGID *int32 `json:"tgid"`
2024-11-10 10:13:38 -05:00
}
func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams) (Talkgroup, error) {
row := q.db.QueryRow(ctx, updateTalkgroup,
arg.Name,
arg.AlphaTag,
2024-11-17 21:46:10 -05:00
arg.TGGroup,
2024-11-10 10:13:38 -05:00
arg.Frequency,
arg.Metadata,
arg.Tags,
arg.Alert,
arg.AlertConfig,
arg.Weight,
2024-11-20 07:26:59 -05:00
arg.Learned,
2024-11-10 10:13:38 -05:00
arg.ID,
2024-11-14 08:37:19 -05:00
arg.SystemID,
2024-11-15 11:34:54 -05:00
arg.TGID,
2024-11-10 10:13:38 -05:00
)
var i Talkgroup
err := row.Scan(
&i.ID,
&i.SystemID,
2024-11-15 11:34:54 -05:00
&i.TGID,
2024-11-10 10:13:38 -05:00
&i.Name,
&i.AlphaTag,
2024-11-17 21:46:10 -05:00
&i.TGGroup,
2024-11-10 10:13:38 -05:00
&i.Frequency,
&i.Metadata,
&i.Tags,
&i.Alert,
&i.AlertConfig,
&i.Weight,
2024-11-17 21:46:10 -05:00
&i.Learned,
2024-11-10 10:13:38 -05:00
)
return i, err
}