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"
|
|
|
|
)
|
|
|
|
|
2024-08-06 11:19:30 -04:00
|
|
|
const bulkSetTalkgroupTags = `-- name: BulkSetTalkgroupTags :exec
|
|
|
|
UPDATE talkgroups SET tags = $2
|
|
|
|
WHERE id = ANY($1)
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) BulkSetTalkgroupTags(ctx context.Context, iD int64, tags []string) error {
|
|
|
|
_, err := q.db.Exec(ctx, bulkSetTalkgroupTags, iD, tags)
|
|
|
|
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-01 09:15:39 -04:00
|
|
|
SELECT id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight FROM talkgroups
|
2024-08-16 16:47:39 -04:00
|
|
|
WHERE id = systg2id($1, $2)
|
2024-08-16 14:54:50 -04:00
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetTalkgroup(ctx context.Context, systemID int, tgid int) (Talkgroup, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getTalkgroup, systemID, tgid)
|
|
|
|
var i Talkgroup
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SystemID,
|
|
|
|
&i.Tgid,
|
|
|
|
&i.Name,
|
2024-08-23 14:28:47 -04:00
|
|
|
&i.AlphaTag,
|
2024-08-16 14:54:50 -04:00
|
|
|
&i.TgGroup,
|
|
|
|
&i.Frequency,
|
|
|
|
&i.Metadata,
|
|
|
|
&i.Tags,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.Alert,
|
|
|
|
&i.AlertConfig,
|
2024-10-25 16:02:08 -04:00
|
|
|
&i.Weight,
|
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"`
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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-08-06 11:19:30 -04:00
|
|
|
WHERE id = systg2id($1, $2)
|
2024-07-17 19:30:16 -04:00
|
|
|
`
|
|
|
|
|
2024-08-06 11:19:30 -04:00
|
|
|
func (q *Queries) GetTalkgroupTags(ctx context.Context, sys int, tg int) ([]string, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getTalkgroupTags, sys, tg)
|
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-08-20 08:17:02 -04:00
|
|
|
tg.id, tg.system_id, sys.name system_name, tg.tgid, tg.name,
|
2024-08-23 14:28:47 -04:00
|
|
|
tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alpha_tag,
|
2024-11-01 09:15:39 -04:00
|
|
|
tg.alert, tg.weight, tg.alert_config,
|
2024-08-16 16:47:39 -04:00
|
|
|
FALSE learned
|
|
|
|
FROM talkgroups tg
|
2024-08-20 08:17:02 -04:00
|
|
|
JOIN systems sys ON tg.system_id = sys.id
|
|
|
|
WHERE tg.id = systg2id($1, $2)
|
2024-08-16 16:47:39 -04:00
|
|
|
UNION
|
|
|
|
SELECT
|
2024-08-20 08:17:02 -04:00
|
|
|
tgl.id::INT8, tgl.system_id::INT4, sys.name system_name, tgl.tgid::INT4, tgl.name,
|
2024-09-02 19:15:58 -04:00
|
|
|
tgl.alpha_tag, NULL::INTEGER, NULL::JSONB,
|
2024-11-01 09:15:39 -04:00
|
|
|
CASE WHEN tgl.alpha_tag IS NULL THEN NULL ELSE ARRAY[tgl.alpha_tag] END, tgl.alpha_tag,
|
|
|
|
TRUE, 1.0, NULL::JSONB,
|
2024-08-16 16:47:39 -04:00
|
|
|
TRUE learned
|
|
|
|
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-01 09:15:39 -04:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
SystemID int32 `json:"system_id"`
|
|
|
|
SystemName string `json:"system_name"`
|
|
|
|
Tgid int32 `json:"tgid"`
|
|
|
|
Name *string `json:"name"`
|
|
|
|
TgGroup *string `json:"tg_group"`
|
|
|
|
Frequency *int32 `json:"frequency"`
|
|
|
|
Metadata []byte `json:"metadata"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
AlphaTag *string `json:"alpha_tag"`
|
|
|
|
Alert bool `json:"alert"`
|
|
|
|
Weight float32 `json:"weight"`
|
|
|
|
AlertConfig []byte `json:"alert_config"`
|
|
|
|
Learned bool `json:"learned"`
|
2024-08-16 16:47:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int, tgid int) (GetTalkgroupWithLearnedRow, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getTalkgroupWithLearned, systemID, tgid)
|
|
|
|
var i GetTalkgroupWithLearnedRow
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SystemID,
|
2024-08-20 08:17:02 -04:00
|
|
|
&i.SystemName,
|
2024-08-16 16:47:39 -04:00
|
|
|
&i.Tgid,
|
|
|
|
&i.Name,
|
|
|
|
&i.TgGroup,
|
|
|
|
&i.Frequency,
|
|
|
|
&i.Metadata,
|
|
|
|
&i.Tags,
|
2024-08-23 14:28:47 -04:00
|
|
|
&i.AlphaTag,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.Alert,
|
2024-10-31 16:14:38 -04:00
|
|
|
&i.Weight,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.AlertConfig,
|
2024-08-16 16:47:39 -04:00
|
|
|
&i.Learned,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-10-31 16:14:38 -04:00
|
|
|
const getTalkgroupWithLearnedByPackedIDs = `-- name: GetTalkgroupWithLearnedByPackedIDs :many
|
|
|
|
SELECT
|
|
|
|
tg.id, tg.system_id, sys.name system_name, tg.tgid, tg.name,
|
|
|
|
tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alpha_tag,
|
2024-11-01 09:15:39 -04:00
|
|
|
tg.alert, tg.weight, tg.alert_config,
|
2024-10-31 16:14:38 -04:00
|
|
|
FALSE learned
|
|
|
|
FROM talkgroups tg
|
|
|
|
JOIN systems sys ON tg.system_id = sys.id
|
|
|
|
WHERE tg.id = ANY($1::INT8[])
|
|
|
|
UNION
|
|
|
|
SELECT
|
|
|
|
tgl.id::INT8, tgl.system_id::INT4, sys.name system_name, tgl.tgid::INT4, tgl.name,
|
|
|
|
tgl.alpha_tag, NULL::INTEGER, NULL::JSONB,
|
2024-11-01 09:15:39 -04:00
|
|
|
CASE WHEN tgl.alpha_tag IS NULL THEN NULL ELSE ARRAY[tgl.alpha_tag] END, tgl.alpha_tag,
|
|
|
|
TRUE, 1.0, NULL::JSONB,
|
2024-10-31 16:14:38 -04:00
|
|
|
TRUE learned
|
|
|
|
FROM talkgroups_learned tgl
|
|
|
|
JOIN systems sys ON tgl.system_id = sys.id
|
|
|
|
WHERE systg2id(tgl.system_id, tgl.tgid) = ANY($1::INT8[]) AND ignored IS NOT TRUE
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetTalkgroupWithLearnedByPackedIDsRow struct {
|
2024-11-01 09:15:39 -04:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
SystemID int32 `json:"system_id"`
|
|
|
|
SystemName string `json:"system_name"`
|
|
|
|
Tgid int32 `json:"tgid"`
|
|
|
|
Name *string `json:"name"`
|
|
|
|
TgGroup *string `json:"tg_group"`
|
|
|
|
Frequency *int32 `json:"frequency"`
|
|
|
|
Metadata []byte `json:"metadata"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
AlphaTag *string `json:"alpha_tag"`
|
|
|
|
Alert bool `json:"alert"`
|
|
|
|
Weight float32 `json:"weight"`
|
|
|
|
AlertConfig []byte `json:"alert_config"`
|
|
|
|
Learned bool `json:"learned"`
|
2024-10-31 16:14:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupWithLearnedByPackedIDsRow, error) {
|
|
|
|
rows, err := q.db.Query(ctx, getTalkgroupWithLearnedByPackedIDs, dollar_1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetTalkgroupWithLearnedByPackedIDsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetTalkgroupWithLearnedByPackedIDsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SystemID,
|
|
|
|
&i.SystemName,
|
|
|
|
&i.Tgid,
|
|
|
|
&i.Name,
|
|
|
|
&i.TgGroup,
|
|
|
|
&i.Frequency,
|
|
|
|
&i.Metadata,
|
|
|
|
&i.Tags,
|
|
|
|
&i.AlphaTag,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.Alert,
|
2024-10-31 16:14:38 -04:00
|
|
|
&i.Weight,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.AlertConfig,
|
2024-10-31 16:14:38 -04:00
|
|
|
&i.Learned,
|
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
2024-10-23 08:55:19 -04:00
|
|
|
const getTalkgroupsByPackedIDs = `-- name: GetTalkgroupsByPackedIDs :many
|
2024-11-01 09:15:39 -04:00
|
|
|
SELECT tg.id, system_id, tgid, tg.name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, sys.id, sys.name FROM talkgroups tg
|
2024-10-23 08:55:19 -04:00
|
|
|
JOIN systems sys ON tg.system_id = sys.id
|
|
|
|
WHERE tg.id = ANY($1::INT8[])
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetTalkgroupsByPackedIDsRow struct {
|
2024-11-01 09:15:39 -04:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
SystemID int32 `json:"system_id"`
|
|
|
|
Tgid int32 `json:"tgid"`
|
|
|
|
Name *string `json:"name"`
|
|
|
|
AlphaTag *string `json:"alpha_tag"`
|
|
|
|
TgGroup *string `json:"tg_group"`
|
|
|
|
Frequency *int32 `json:"frequency"`
|
|
|
|
Metadata []byte `json:"metadata"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Alert bool `json:"alert"`
|
|
|
|
AlertConfig []byte `json:"alert_config"`
|
|
|
|
Weight float32 `json:"weight"`
|
|
|
|
ID_2 int `json:"id_2"`
|
|
|
|
Name_2 string `json:"name_2"`
|
2024-10-23 08:55:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupsByPackedIDsRow, error) {
|
|
|
|
rows, err := q.db.Query(ctx, getTalkgroupsByPackedIDs, dollar_1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetTalkgroupsByPackedIDsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetTalkgroupsByPackedIDsRow
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.SystemID,
|
|
|
|
&i.Tgid,
|
|
|
|
&i.Name,
|
|
|
|
&i.AlphaTag,
|
|
|
|
&i.TgGroup,
|
|
|
|
&i.Frequency,
|
|
|
|
&i.Metadata,
|
|
|
|
&i.Tags,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.Alert,
|
|
|
|
&i.AlertConfig,
|
2024-10-25 16:02:08 -04:00
|
|
|
&i.Weight,
|
2024-10-23 08:55:19 -04:00
|
|
|
&i.ID_2,
|
|
|
|
&i.Name_2,
|
|
|
|
); err != nil {
|
|
|
|
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 getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
|
2024-11-01 09:15:39 -04:00
|
|
|
SELECT id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight FROM talkgroups
|
2024-07-17 19:30:16 -04:00
|
|
|
WHERE tags && ARRAY[$1]
|
|
|
|
`
|
|
|
|
|
2024-07-28 23:07:04 -04:00
|
|
|
func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]Talkgroup, 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-28 23:07:04 -04:00
|
|
|
var items []Talkgroup
|
2024-07-17 19:30:16 -04:00
|
|
|
for rows.Next() {
|
2024-07-28 23:07:04 -04:00
|
|
|
var i Talkgroup
|
|
|
|
if err := rows.Scan(
|
2024-08-06 11:19:30 -04:00
|
|
|
&i.ID,
|
2024-07-28 23:07:04 -04:00
|
|
|
&i.SystemID,
|
|
|
|
&i.Tgid,
|
|
|
|
&i.Name,
|
2024-08-23 14:28:47 -04:00
|
|
|
&i.AlphaTag,
|
2024-07-28 23:07:04 -04:00
|
|
|
&i.TgGroup,
|
|
|
|
&i.Frequency,
|
|
|
|
&i.Metadata,
|
|
|
|
&i.Tags,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.Alert,
|
|
|
|
&i.AlertConfig,
|
2024-10-25 16:02:08 -04:00
|
|
|
&i.Weight,
|
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 getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
|
2024-11-01 09:15:39 -04:00
|
|
|
SELECT id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight FROM talkgroups
|
2024-07-17 19:30:16 -04:00
|
|
|
WHERE tags @> ARRAY[$1]
|
|
|
|
`
|
|
|
|
|
2024-07-28 23:07:04 -04:00
|
|
|
func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]Talkgroup, 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-28 23:07:04 -04:00
|
|
|
var items []Talkgroup
|
2024-07-17 19:30:16 -04:00
|
|
|
for rows.Next() {
|
2024-07-28 23:07:04 -04:00
|
|
|
var i Talkgroup
|
|
|
|
if err := rows.Scan(
|
2024-08-06 11:19:30 -04:00
|
|
|
&i.ID,
|
2024-07-28 23:07:04 -04:00
|
|
|
&i.SystemID,
|
|
|
|
&i.Tgid,
|
|
|
|
&i.Name,
|
2024-08-23 14:28:47 -04:00
|
|
|
&i.AlphaTag,
|
2024-07-28 23:07:04 -04:00
|
|
|
&i.TgGroup,
|
|
|
|
&i.Frequency,
|
|
|
|
&i.Metadata,
|
|
|
|
&i.Tags,
|
2024-11-01 09:15:39 -04:00
|
|
|
&i.Alert,
|
|
|
|
&i.AlertConfig,
|
2024-10-25 16:02:08 -04:00
|
|
|
&i.Weight,
|
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-08-06 11:19:30 -04:00
|
|
|
UPDATE talkgroups SET tags = $3
|
|
|
|
WHERE id = systg2id($1, $2)
|
2024-07-17 19:30:16 -04:00
|
|
|
`
|
|
|
|
|
2024-08-06 11:19:30 -04:00
|
|
|
func (q *Queries) SetTalkgroupTags(ctx context.Context, sys int, tg int, tags []string) error {
|
|
|
|
_, err := q.db.Exec(ctx, setTalkgroupTags, sys, tg, tags)
|
2024-07-17 19:30:16 -04:00
|
|
|
return err
|
|
|
|
}
|