From 57449e99a03a403a985529872a2946d17ed2c0f4 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Wed, 17 Jul 2024 19:40:21 -0400 Subject: [PATCH] Get IDs --- pkg/gordio/database/talkgroups.sql.go | 24 ++++++++++++------------ sql/postgres/queries/talkgroups.sql | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/gordio/database/talkgroups.sql.go b/pkg/gordio/database/talkgroups.sql.go index f8a3091..9efa182 100644 --- a/pkg/gordio/database/talkgroups.sql.go +++ b/pkg/gordio/database/talkgroups.sql.go @@ -22,23 +22,23 @@ func (q *Queries) GetTalkgroupTags(ctx context.Context, talkgroupID int32) ([]st } const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many -SELECT talkgroup_id, tags FROM talkgroups_tags +SELECT talkgroup_id FROM talkgroups_tags WHERE tags && ARRAY[$1] ` -func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]TalkgroupsTag, error) { +func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]int32, error) { rows, err := q.db.Query(ctx, getTalkgroupsWithAllTags, tags) if err != nil { return nil, err } defer rows.Close() - var items []TalkgroupsTag + var items []int32 for rows.Next() { - var i TalkgroupsTag - if err := rows.Scan(&i.TalkgroupID, &i.Tags); err != nil { + var talkgroup_id int32 + if err := rows.Scan(&talkgroup_id); err != nil { return nil, err } - items = append(items, i) + items = append(items, talkgroup_id) } if err := rows.Err(); err != nil { return nil, err @@ -47,23 +47,23 @@ func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ( } const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many -SELECT talkgroup_id, tags FROM talkgroups_tags +SELECT talkgroup_id FROM talkgroups_tags WHERE tags @> ARRAY[$1] ` -func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]TalkgroupsTag, error) { +func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]int32, error) { rows, err := q.db.Query(ctx, getTalkgroupsWithAnyTags, tags) if err != nil { return nil, err } defer rows.Close() - var items []TalkgroupsTag + var items []int32 for rows.Next() { - var i TalkgroupsTag - if err := rows.Scan(&i.TalkgroupID, &i.Tags); err != nil { + var talkgroup_id int32 + if err := rows.Scan(&talkgroup_id); err != nil { return nil, err } - items = append(items, i) + items = append(items, talkgroup_id) } if err := rows.Err(); err != nil { return nil, err diff --git a/sql/postgres/queries/talkgroups.sql b/sql/postgres/queries/talkgroups.sql index 05e245f..1d57b50 100644 --- a/sql/postgres/queries/talkgroups.sql +++ b/sql/postgres/queries/talkgroups.sql @@ -1,9 +1,9 @@ -- name: GetTalkgroupsWithAnyTags :many -SELECT * FROM talkgroups_tags +SELECT talkgroup_id FROM talkgroups_tags WHERE tags @> ARRAY[$1]; -- name: GetTalkgroupsWithAllTags :many -SELECT * FROM talkgroups_tags +SELECT talkgroup_id FROM talkgroups_tags WHERE tags && ARRAY[$1]; -- name: GetTalkgroupTags :one