diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-07 15:04:52 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-07 15:07:34 +0530 |
commit | 60aa1b7adbd133a5b1679ab2feac4ec17e3b48b5 (patch) | |
tree | 082f64ac3ef625fb364227c138a99ba5c571016b /db/query.sql.go | |
parent | 38bf443cb2f52bd4cc822e69f9339094d846396f (diff) |
dns: block blacklisted domains in the database
Diffstat (limited to 'db/query.sql.go')
-rw-r--r-- | db/query.sql.go | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/db/query.sql.go b/db/query.sql.go index d6304a7..80c6469 100644 --- a/db/query.sql.go +++ b/db/query.sql.go @@ -11,6 +11,19 @@ import ( "github.com/jackc/pgx/v5/pgtype" ) +const enterDnsBlackList = `-- name: EnterDnsBlackList :exec +INSERT INTO DnsBlackList ( + Name +) VALUES ( + $1 +) +` + +func (q *Queries) EnterDnsBlackList(ctx context.Context, name string) error { + _, err := q.db.Exec(ctx, enterDnsBlackList, name) + return err +} + const enterUsage = `-- name: EnterUsage :exec INSERT INTO Usage ( HardwareAddr, StartTime, StopTime, Egress, Ingress @@ -38,8 +51,34 @@ func (q *Queries) EnterUsage(ctx context.Context, arg EnterUsageParams) error { return err } +const getDnsBlackList = `-- name: GetDnsBlackList :many +SELECT name +FROM DnsBlackList +` + +func (q *Queries) GetDnsBlackList(ctx context.Context) ([]string, error) { + rows, err := q.db.Query(ctx, getDnsBlackList) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getUsage = `-- name: GetUsage :one -SELECT SUM(Ingress) AS Ingress, SUM(Egress) AS Egress FROM Usage +SELECT SUM(Ingress) AS Ingress, SUM(Egress) AS Egress +FROM Usage ` type GetUsageRow struct { |