Use sqlc.embed
This commit is contained in:
parent
1f8fe24dd2
commit
8afc687d4f
7 changed files with 141 additions and 169 deletions
|
@ -170,10 +170,10 @@ func (as *alerter) eval(ctx context.Context, now time.Time, testMode bool) ([]Al
|
||||||
origScore := s.Score
|
origScore := s.Score
|
||||||
tgr, has := as.tgCache.TG(ctx, s.ID)
|
tgr, has := as.tgCache.TG(ctx, s.ID)
|
||||||
if has {
|
if has {
|
||||||
if !tgr.Alert {
|
if !tgr.Talkgroup.Alert {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.Score *= float64(tgr.Weight)
|
s.Score *= float64(tgr.Talkgroup.Weight)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Score > as.cfg.AlertThreshold || testMode {
|
if s.Score > as.cfg.AlertThreshold || testMode {
|
||||||
|
@ -330,15 +330,15 @@ func (as *alerter) makeAlert(ctx context.Context, score trending.Score[talkgroup
|
||||||
tgRecord, has := as.tgCache.TG(ctx, score.ID)
|
tgRecord, has := as.tgCache.TG(ctx, score.ID)
|
||||||
switch has {
|
switch has {
|
||||||
case true:
|
case true:
|
||||||
d.Weight = tgRecord.Weight
|
d.Weight = tgRecord.Talkgroup.Weight
|
||||||
if tgRecord.SystemName == "" {
|
if tgRecord.System.Name == "" {
|
||||||
tgRecord.SystemName = strconv.Itoa(int(score.ID.System))
|
tgRecord.System.Name = strconv.Itoa(int(score.ID.System))
|
||||||
}
|
}
|
||||||
|
|
||||||
if tgRecord.Name != nil {
|
if tgRecord.Talkgroup.Name != nil {
|
||||||
d.TGName = fmt.Sprintf("%s %s (%d)", tgRecord.SystemName, *tgRecord.Name, score.ID.Talkgroup)
|
d.TGName = fmt.Sprintf("%s %s (%d)", tgRecord.System.Name, *tgRecord.Talkgroup.Name, score.ID.Talkgroup)
|
||||||
} else {
|
} else {
|
||||||
d.TGName = fmt.Sprintf("%s:%d", tgRecord.SystemName, int(score.ID.Talkgroup))
|
d.TGName = fmt.Sprintf("%s:%d", tgRecord.System.Name, int(score.ID.Talkgroup))
|
||||||
}
|
}
|
||||||
case false:
|
case false:
|
||||||
system, has := as.tgCache.SystemName(ctx, int(score.ID.System))
|
system, has := as.tgCache.SystemName(ctx, int(score.ID.System))
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (as *alerter) tgStatsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
tgMap := make(map[talkgroups.ID]database.GetTalkgroupsByPackedIDsRow, len(tgs))
|
tgMap := make(map[talkgroups.ID]database.GetTalkgroupsByPackedIDsRow, len(tgs))
|
||||||
for _, t := range tgs {
|
for _, t := range tgs {
|
||||||
tgMap[talkgroups.ID{System: uint32(t.SystemID), Talkgroup: uint32(t.ID)}] = t
|
tgMap[talkgroups.ID{System: uint32(t.System.ID), Talkgroup: uint32(t.Talkgroup.ID)}] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
renderData := struct {
|
renderData := struct {
|
||||||
|
|
|
@ -22,14 +22,14 @@ type Querier interface {
|
||||||
GetAPIKey(ctx context.Context, apiKey string) (ApiKey, error)
|
GetAPIKey(ctx context.Context, apiKey string) (ApiKey, error)
|
||||||
GetDatabaseSize(ctx context.Context) (string, error)
|
GetDatabaseSize(ctx context.Context) (string, error)
|
||||||
GetSystemName(ctx context.Context, systemID int) (string, error)
|
GetSystemName(ctx context.Context, systemID int) (string, error)
|
||||||
GetTalkgroup(ctx context.Context, systemID int, tgid int) (Talkgroup, error)
|
GetTalkgroup(ctx context.Context, systemID int, tgid int) (GetTalkgroupRow, error)
|
||||||
GetTalkgroupIDsByTags(ctx context.Context, anytags []string, alltags []string, nottags []string) ([]GetTalkgroupIDsByTagsRow, error)
|
GetTalkgroupIDsByTags(ctx context.Context, anytags []string, alltags []string, nottags []string) ([]GetTalkgroupIDsByTagsRow, error)
|
||||||
GetTalkgroupTags(ctx context.Context, sys int, tg int) ([]string, error)
|
GetTalkgroupTags(ctx context.Context, sys int, tg int) ([]string, error)
|
||||||
GetTalkgroupWithLearned(ctx context.Context, systemID int, tgid int) (GetTalkgroupWithLearnedRow, error)
|
GetTalkgroupWithLearned(ctx context.Context, systemID int, tgid int) (GetTalkgroupWithLearnedRow, error)
|
||||||
GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupWithLearnedByPackedIDsRow, error)
|
GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupWithLearnedByPackedIDsRow, error)
|
||||||
GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupsByPackedIDsRow, error)
|
GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupsByPackedIDsRow, error)
|
||||||
GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]Talkgroup, error)
|
GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAllTagsRow, error)
|
||||||
GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]Talkgroup, error)
|
GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]GetTalkgroupsWithAnyTagsRow, error)
|
||||||
GetUserByID(ctx context.Context, id int32) (User, error)
|
GetUserByID(ctx context.Context, id int32) (User, error)
|
||||||
GetUserByUID(ctx context.Context, id int32) (User, error)
|
GetUserByUID(ctx context.Context, id int32) (User, error)
|
||||||
GetUserByUsername(ctx context.Context, username string) (User, error)
|
GetUserByUsername(ctx context.Context, username string) (User, error)
|
||||||
|
|
|
@ -31,26 +31,30 @@ func (q *Queries) GetSystemName(ctx context.Context, systemID int) (string, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTalkgroup = `-- name: GetTalkgroup :one
|
const getTalkgroup = `-- name: GetTalkgroup :one
|
||||||
SELECT id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight FROM talkgroups
|
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 FROM talkgroups
|
||||||
WHERE id = systg2id($1, $2)
|
WHERE id = systg2id($1, $2)
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetTalkgroup(ctx context.Context, systemID int, tgid int) (Talkgroup, error) {
|
type GetTalkgroupRow struct {
|
||||||
|
Talkgroup Talkgroup `json:"talkgroup"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetTalkgroup(ctx context.Context, systemID int, tgid int) (GetTalkgroupRow, error) {
|
||||||
row := q.db.QueryRow(ctx, getTalkgroup, systemID, tgid)
|
row := q.db.QueryRow(ctx, getTalkgroup, systemID, tgid)
|
||||||
var i Talkgroup
|
var i GetTalkgroupRow
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.Talkgroup.ID,
|
||||||
&i.SystemID,
|
&i.Talkgroup.SystemID,
|
||||||
&i.Tgid,
|
&i.Talkgroup.Tgid,
|
||||||
&i.Name,
|
&i.Talkgroup.Name,
|
||||||
&i.AlphaTag,
|
&i.Talkgroup.AlphaTag,
|
||||||
&i.TgGroup,
|
&i.Talkgroup.TgGroup,
|
||||||
&i.Frequency,
|
&i.Talkgroup.Frequency,
|
||||||
&i.Metadata,
|
&i.Talkgroup.Metadata,
|
||||||
&i.Tags,
|
&i.Talkgroup.Tags,
|
||||||
&i.Alert,
|
&i.Talkgroup.Alert,
|
||||||
&i.AlertConfig,
|
&i.Talkgroup.AlertConfig,
|
||||||
&i.Weight,
|
&i.Talkgroup.Weight,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
@ -101,9 +105,7 @@ func (q *Queries) GetTalkgroupTags(ctx context.Context, sys int, tg int) ([]stri
|
||||||
|
|
||||||
const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one
|
const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one
|
||||||
SELECT
|
SELECT
|
||||||
tg.id, tg.system_id, sys.name system_name, tg.tgid, tg.name,
|
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, sys.id, sys.name,
|
||||||
tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alpha_tag,
|
|
||||||
tg.alert, tg.weight, tg.alert_config,
|
|
||||||
FALSE learned
|
FALSE learned
|
||||||
FROM talkgroups tg
|
FROM talkgroups tg
|
||||||
JOIN systems sys ON tg.system_id = sys.id
|
JOIN systems sys ON tg.system_id = sys.id
|
||||||
|
@ -121,39 +123,29 @@ WHERE tgl.system_id = $1 AND tgl.tgid = $2 AND ignored IS NOT TRUE
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetTalkgroupWithLearnedRow struct {
|
type GetTalkgroupWithLearnedRow struct {
|
||||||
ID int64 `json:"id"`
|
Talkgroup Talkgroup `json:"talkgroup"`
|
||||||
SystemID int32 `json:"system_id"`
|
System System `json:"system"`
|
||||||
SystemName string `json:"system_name"`
|
Learned bool `json:"learned"`
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int, tgid int) (GetTalkgroupWithLearnedRow, error) {
|
func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int, tgid int) (GetTalkgroupWithLearnedRow, error) {
|
||||||
row := q.db.QueryRow(ctx, getTalkgroupWithLearned, systemID, tgid)
|
row := q.db.QueryRow(ctx, getTalkgroupWithLearned, systemID, tgid)
|
||||||
var i GetTalkgroupWithLearnedRow
|
var i GetTalkgroupWithLearnedRow
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.Talkgroup.ID,
|
||||||
&i.SystemID,
|
&i.Talkgroup.SystemID,
|
||||||
&i.SystemName,
|
&i.Talkgroup.Tgid,
|
||||||
&i.Tgid,
|
&i.Talkgroup.Name,
|
||||||
&i.Name,
|
&i.Talkgroup.AlphaTag,
|
||||||
&i.TgGroup,
|
&i.Talkgroup.TgGroup,
|
||||||
&i.Frequency,
|
&i.Talkgroup.Frequency,
|
||||||
&i.Metadata,
|
&i.Talkgroup.Metadata,
|
||||||
&i.Tags,
|
&i.Talkgroup.Tags,
|
||||||
&i.AlphaTag,
|
&i.Talkgroup.Alert,
|
||||||
&i.Alert,
|
&i.Talkgroup.AlertConfig,
|
||||||
&i.Weight,
|
&i.Talkgroup.Weight,
|
||||||
&i.AlertConfig,
|
&i.System.ID,
|
||||||
|
&i.System.Name,
|
||||||
&i.Learned,
|
&i.Learned,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
|
@ -161,9 +153,7 @@ func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int, tgi
|
||||||
|
|
||||||
const getTalkgroupWithLearnedByPackedIDs = `-- name: GetTalkgroupWithLearnedByPackedIDs :many
|
const getTalkgroupWithLearnedByPackedIDs = `-- name: GetTalkgroupWithLearnedByPackedIDs :many
|
||||||
SELECT
|
SELECT
|
||||||
tg.id, tg.system_id, sys.name system_name, tg.tgid, tg.name,
|
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, sys.id, sys.name,
|
||||||
tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alpha_tag,
|
|
||||||
tg.alert, tg.weight, tg.alert_config,
|
|
||||||
FALSE learned
|
FALSE learned
|
||||||
FROM talkgroups tg
|
FROM talkgroups tg
|
||||||
JOIN systems sys ON tg.system_id = sys.id
|
JOIN systems sys ON tg.system_id = sys.id
|
||||||
|
@ -181,20 +171,9 @@ WHERE systg2id(tgl.system_id, tgl.tgid) = ANY($1::INT8[]) AND ignored IS NOT TRU
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetTalkgroupWithLearnedByPackedIDsRow struct {
|
type GetTalkgroupWithLearnedByPackedIDsRow struct {
|
||||||
ID int64 `json:"id"`
|
Talkgroup Talkgroup `json:"talkgroup"`
|
||||||
SystemID int32 `json:"system_id"`
|
System System `json:"system"`
|
||||||
SystemName string `json:"system_name"`
|
Learned bool `json:"learned"`
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupWithLearnedByPackedIDsRow, error) {
|
func (q *Queries) GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupWithLearnedByPackedIDsRow, error) {
|
||||||
|
@ -207,19 +186,20 @@ func (q *Queries) GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i GetTalkgroupWithLearnedByPackedIDsRow
|
var i GetTalkgroupWithLearnedByPackedIDsRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.Talkgroup.ID,
|
||||||
&i.SystemID,
|
&i.Talkgroup.SystemID,
|
||||||
&i.SystemName,
|
&i.Talkgroup.Tgid,
|
||||||
&i.Tgid,
|
&i.Talkgroup.Name,
|
||||||
&i.Name,
|
&i.Talkgroup.AlphaTag,
|
||||||
&i.TgGroup,
|
&i.Talkgroup.TgGroup,
|
||||||
&i.Frequency,
|
&i.Talkgroup.Frequency,
|
||||||
&i.Metadata,
|
&i.Talkgroup.Metadata,
|
||||||
&i.Tags,
|
&i.Talkgroup.Tags,
|
||||||
&i.AlphaTag,
|
&i.Talkgroup.Alert,
|
||||||
&i.Alert,
|
&i.Talkgroup.AlertConfig,
|
||||||
&i.Weight,
|
&i.Talkgroup.Weight,
|
||||||
&i.AlertConfig,
|
&i.System.ID,
|
||||||
|
&i.System.Name,
|
||||||
&i.Learned,
|
&i.Learned,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -233,26 +213,14 @@ func (q *Queries) GetTalkgroupWithLearnedByPackedIDs(ctx context.Context, dollar
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTalkgroupsByPackedIDs = `-- name: GetTalkgroupsByPackedIDs :many
|
const getTalkgroupsByPackedIDs = `-- name: GetTalkgroupsByPackedIDs :many
|
||||||
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
|
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, sys.id, sys.name FROM talkgroups tg
|
||||||
JOIN systems sys ON tg.system_id = sys.id
|
JOIN systems sys ON tg.system_id = sys.id
|
||||||
WHERE tg.id = ANY($1::INT8[])
|
WHERE tg.id = ANY($1::INT8[])
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetTalkgroupsByPackedIDsRow struct {
|
type GetTalkgroupsByPackedIDsRow struct {
|
||||||
ID int64 `json:"id"`
|
Talkgroup Talkgroup `json:"talkgroup"`
|
||||||
SystemID int32 `json:"system_id"`
|
System System `json:"system"`
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupsByPackedIDsRow, error) {
|
func (q *Queries) GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64) ([]GetTalkgroupsByPackedIDsRow, error) {
|
||||||
|
@ -265,20 +233,20 @@ func (q *Queries) GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i GetTalkgroupsByPackedIDsRow
|
var i GetTalkgroupsByPackedIDsRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.Talkgroup.ID,
|
||||||
&i.SystemID,
|
&i.Talkgroup.SystemID,
|
||||||
&i.Tgid,
|
&i.Talkgroup.Tgid,
|
||||||
&i.Name,
|
&i.Talkgroup.Name,
|
||||||
&i.AlphaTag,
|
&i.Talkgroup.AlphaTag,
|
||||||
&i.TgGroup,
|
&i.Talkgroup.TgGroup,
|
||||||
&i.Frequency,
|
&i.Talkgroup.Frequency,
|
||||||
&i.Metadata,
|
&i.Talkgroup.Metadata,
|
||||||
&i.Tags,
|
&i.Talkgroup.Tags,
|
||||||
&i.Alert,
|
&i.Talkgroup.Alert,
|
||||||
&i.AlertConfig,
|
&i.Talkgroup.AlertConfig,
|
||||||
&i.Weight,
|
&i.Talkgroup.Weight,
|
||||||
&i.ID_2,
|
&i.System.ID,
|
||||||
&i.Name_2,
|
&i.System.Name,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -291,32 +259,36 @@ func (q *Queries) GetTalkgroupsByPackedIDs(ctx context.Context, dollar_1 []int64
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
|
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
|
||||||
SELECT id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight FROM talkgroups
|
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 FROM talkgroups
|
||||||
WHERE tags && ARRAY[$1]
|
WHERE tags && ARRAY[$1]
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]Talkgroup, error) {
|
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)
|
rows, err := q.db.Query(ctx, getTalkgroupsWithAllTags, tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var items []Talkgroup
|
var items []GetTalkgroupsWithAllTagsRow
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i Talkgroup
|
var i GetTalkgroupsWithAllTagsRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.Talkgroup.ID,
|
||||||
&i.SystemID,
|
&i.Talkgroup.SystemID,
|
||||||
&i.Tgid,
|
&i.Talkgroup.Tgid,
|
||||||
&i.Name,
|
&i.Talkgroup.Name,
|
||||||
&i.AlphaTag,
|
&i.Talkgroup.AlphaTag,
|
||||||
&i.TgGroup,
|
&i.Talkgroup.TgGroup,
|
||||||
&i.Frequency,
|
&i.Talkgroup.Frequency,
|
||||||
&i.Metadata,
|
&i.Talkgroup.Metadata,
|
||||||
&i.Tags,
|
&i.Talkgroup.Tags,
|
||||||
&i.Alert,
|
&i.Talkgroup.Alert,
|
||||||
&i.AlertConfig,
|
&i.Talkgroup.AlertConfig,
|
||||||
&i.Weight,
|
&i.Talkgroup.Weight,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -329,32 +301,36 @@ func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
|
const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
|
||||||
SELECT id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight FROM talkgroups
|
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 FROM talkgroups
|
||||||
WHERE tags @> ARRAY[$1]
|
WHERE tags @> ARRAY[$1]
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]Talkgroup, error) {
|
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)
|
rows, err := q.db.Query(ctx, getTalkgroupsWithAnyTags, tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var items []Talkgroup
|
var items []GetTalkgroupsWithAnyTagsRow
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i Talkgroup
|
var i GetTalkgroupsWithAnyTagsRow
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.Talkgroup.ID,
|
||||||
&i.SystemID,
|
&i.Talkgroup.SystemID,
|
||||||
&i.Tgid,
|
&i.Talkgroup.Tgid,
|
||||||
&i.Name,
|
&i.Talkgroup.Name,
|
||||||
&i.AlphaTag,
|
&i.Talkgroup.AlphaTag,
|
||||||
&i.TgGroup,
|
&i.Talkgroup.TgGroup,
|
||||||
&i.Frequency,
|
&i.Talkgroup.Frequency,
|
||||||
&i.Metadata,
|
&i.Talkgroup.Metadata,
|
||||||
&i.Tags,
|
&i.Talkgroup.Tags,
|
||||||
&i.Alert,
|
&i.Talkgroup.Alert,
|
||||||
&i.AlertConfig,
|
&i.Talkgroup.AlertConfig,
|
||||||
&i.Weight,
|
&i.Talkgroup.Weight,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,9 +71,9 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var md *structpb.Struct
|
var md *structpb.Struct
|
||||||
if len(tgi.Metadata) > 0 {
|
if len(tgi.Talkgroup.Metadata) > 0 {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
err := json.Unmarshal(tgi.Metadata, &m)
|
err := json.Unmarshal(tgi.Talkgroup.Metadata, &m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("unmarshal tg metadata")
|
log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("unmarshal tg metadata")
|
||||||
}
|
}
|
||||||
|
@ -85,14 +85,14 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error {
|
||||||
|
|
||||||
resp := &pb.TalkgroupInfo{
|
resp := &pb.TalkgroupInfo{
|
||||||
Tg: tg,
|
Tg: tg,
|
||||||
Name: tgi.Name,
|
Name: tgi.Talkgroup.Name,
|
||||||
Group: tgi.TgGroup,
|
Group: tgi.Talkgroup.TgGroup,
|
||||||
Frequency: tgi.Frequency,
|
Frequency: tgi.Talkgroup.Frequency,
|
||||||
Metadata: md,
|
Metadata: md,
|
||||||
Tags: tgi.Tags,
|
Tags: tgi.Talkgroup.Tags,
|
||||||
Learned: tgi.Learned,
|
Learned: tgi.Learned,
|
||||||
AlphaTag: tgi.AlphaTag,
|
AlphaTag: tgi.Talkgroup.AlphaTag,
|
||||||
SystemName: tgi.SystemName,
|
SystemName: tgi.System.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = c.Send(&pb.Message{
|
_ = c.Send(&pb.Message{
|
||||||
|
|
|
@ -90,11 +90,11 @@ func (t *cache) Hint(ctx context.Context, tgs []ID) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *cache) add(rec database.GetTalkgroupWithLearnedByPackedIDsRow) error {
|
func (t *cache) add(rec database.GetTalkgroupWithLearnedByPackedIDsRow) error {
|
||||||
tg := TG(rec.SystemID, rec.Tgid)
|
tg := TG(rec.System.ID, int(rec.Talkgroup.Tgid))
|
||||||
t.tgs[tg] = rec
|
t.tgs[tg] = rec
|
||||||
t.systems[rec.SystemID] = rec.SystemName
|
t.systems[int32(rec.System.ID)] = rec.System.Name
|
||||||
|
|
||||||
return t.AlertConfig.AddAlertConfig(tg, rec.AlertConfig)
|
return t.AlertConfig.AddAlertConfig(tg, rec.Talkgroup.AlertConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *cache) Load(ctx context.Context, tgs []int64) error {
|
func (t *cache) Load(ctx context.Context, tgs []int64) error {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
-- name: GetTalkgroupsWithAnyTags :many
|
-- name: GetTalkgroupsWithAnyTags :many
|
||||||
SELECT * FROM talkgroups
|
SELECT sqlc.embed(talkgroups) FROM talkgroups
|
||||||
WHERE tags @> ARRAY[$1];
|
WHERE tags @> ARRAY[$1];
|
||||||
|
|
||||||
-- name: GetTalkgroupsWithAllTags :many
|
-- name: GetTalkgroupsWithAllTags :many
|
||||||
SELECT * FROM talkgroups
|
SELECT sqlc.embed(talkgroups) FROM talkgroups
|
||||||
WHERE tags && ARRAY[$1];
|
WHERE tags && ARRAY[$1];
|
||||||
|
|
||||||
-- name: GetTalkgroupIDsByTags :many
|
-- name: GetTalkgroupIDsByTags :many
|
||||||
|
@ -25,19 +25,17 @@ UPDATE talkgroups SET tags = $2
|
||||||
WHERE id = ANY($1);
|
WHERE id = ANY($1);
|
||||||
|
|
||||||
-- name: GetTalkgroup :one
|
-- name: GetTalkgroup :one
|
||||||
SELECT * FROM talkgroups
|
SELECT sqlc.embed(talkgroups) FROM talkgroups
|
||||||
WHERE id = systg2id(sqlc.arg(system_id), sqlc.arg(tgid));
|
WHERE id = systg2id(sqlc.arg(system_id), sqlc.arg(tgid));
|
||||||
|
|
||||||
-- name: GetTalkgroupsByPackedIDs :many
|
-- name: GetTalkgroupsByPackedIDs :many
|
||||||
SELECT * FROM talkgroups tg
|
SELECT sqlc.embed(tg), sqlc.embed(sys) FROM talkgroups tg
|
||||||
JOIN systems sys ON tg.system_id = sys.id
|
JOIN systems sys ON tg.system_id = sys.id
|
||||||
WHERE tg.id = ANY($1::INT8[]);
|
WHERE tg.id = ANY($1::INT8[]);
|
||||||
|
|
||||||
-- name: GetTalkgroupWithLearned :one
|
-- name: GetTalkgroupWithLearned :one
|
||||||
SELECT
|
SELECT
|
||||||
tg.id, tg.system_id, sys.name system_name, tg.tgid, tg.name,
|
sqlc.embed(tg), sqlc.embed(sys),
|
||||||
tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alpha_tag,
|
|
||||||
tg.alert, tg.weight, tg.alert_config,
|
|
||||||
FALSE learned
|
FALSE learned
|
||||||
FROM talkgroups tg
|
FROM talkgroups tg
|
||||||
JOIN systems sys ON tg.system_id = sys.id
|
JOIN systems sys ON tg.system_id = sys.id
|
||||||
|
@ -55,9 +53,7 @@ WHERE tgl.system_id = sqlc.arg(system_id) AND tgl.tgid = sqlc.arg(tgid) AND igno
|
||||||
|
|
||||||
-- name: GetTalkgroupWithLearnedByPackedIDs :many
|
-- name: GetTalkgroupWithLearnedByPackedIDs :many
|
||||||
SELECT
|
SELECT
|
||||||
tg.id, tg.system_id, sys.name system_name, tg.tgid, tg.name,
|
sqlc.embed(tg), sqlc.embed(sys),
|
||||||
tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alpha_tag,
|
|
||||||
tg.alert, tg.weight, tg.alert_config,
|
|
||||||
FALSE learned
|
FALSE learned
|
||||||
FROM talkgroups tg
|
FROM talkgroups tg
|
||||||
JOIN systems sys ON tg.system_id = sys.id
|
JOIN systems sys ON tg.system_id = sys.id
|
||||||
|
|
Loading…
Reference in a new issue