mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-04 19:45:14 -04:00
39 lines
768 B
Go
39 lines
768 B
Go
package networkmap_pgsql
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
const (
|
|
GetDomainsQuery = `
|
|
select domain, target_cluster
|
|
from domains
|
|
where account_id=$1
|
|
`
|
|
)
|
|
|
|
func (pg *PgStore) GetDomains(ctx context.Context, accountId string) ([]domain, error) {
|
|
c, err := pg.Pool.Acquire(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return GetDomainsViaPgxConnection(ctx, c.Conn(), accountId)
|
|
}
|
|
|
|
func GetDomainsViaPgxConnection(ctx context.Context, conn *pgx.Conn, accountId string) ([]domain, error) {
|
|
rows, err := conn.Query(ctx, GetDomainsQuery, accountId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return pgx.CollectRows(rows, pgx.RowToStructByName[domain])
|
|
}
|
|
|
|
type domain struct {
|
|
Domain sql.NullString
|
|
TargetCluster sql.NullString
|
|
}
|