summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/models.go4
-rw-r--r--db/query.sql14
-rw-r--r--db/query.sql.go47
-rw-r--r--db/schema.sql4
4 files changed, 69 insertions, 0 deletions
diff --git a/db/models.go b/db/models.go
index 1ea2797..3beb527 100644
--- a/db/models.go
+++ b/db/models.go
@@ -12,6 +12,10 @@ type Dnsblacklist struct {
Name string
}
+type Macblacklist struct {
+ Hardwareaddr int64
+}
+
type Usage struct {
Hardwareaddr int64
Starttime pgtype.Timestamp
diff --git a/db/query.sql b/db/query.sql
index f4b17dd..624442f 100644
--- a/db/query.sql
+++ b/db/query.sql
@@ -21,3 +21,17 @@ WHERE Name = $1;
-- name: GetDnsBlackList :many
SELECT * FROM DnsBlackList;
+
+-- name: EnterMacBlackList :exec
+INSERT INTO MacBlackList (
+ HardwareAddr
+) VALUES (
+ $1
+);
+
+-- name: DeleteMacBlackList :exec
+DELETE FROM MacBlackList
+WHERE HardwareAddr = $1;
+
+-- name: GetMacBlackList :many
+SELECT * FROM MacBlackList;
diff --git a/db/query.sql.go b/db/query.sql.go
index 7c28723..57bee9f 100644
--- a/db/query.sql.go
+++ b/db/query.sql.go
@@ -21,6 +21,16 @@ func (q *Queries) DeleteDnsBlackList(ctx context.Context, name string) error {
return err
}
+const deleteMacBlackList = `-- name: DeleteMacBlackList :exec
+DELETE FROM MacBlackList
+WHERE HardwareAddr = $1
+`
+
+func (q *Queries) DeleteMacBlackList(ctx context.Context, hardwareaddr int64) error {
+ _, err := q.db.Exec(ctx, deleteMacBlackList, hardwareaddr)
+ return err
+}
+
const enterDnsBlackList = `-- name: EnterDnsBlackList :exec
INSERT INTO DnsBlackList (
Name
@@ -34,6 +44,19 @@ func (q *Queries) EnterDnsBlackList(ctx context.Context, name string) error {
return err
}
+const enterMacBlackList = `-- name: EnterMacBlackList :exec
+INSERT INTO MacBlackList (
+ HardwareAddr
+) VALUES (
+ $1
+)
+`
+
+func (q *Queries) EnterMacBlackList(ctx context.Context, hardwareaddr int64) error {
+ _, err := q.db.Exec(ctx, enterMacBlackList, hardwareaddr)
+ return err
+}
+
const enterUsage = `-- name: EnterUsage :exec
INSERT INTO Usage (
HardwareAddr, StartTime, StopTime, Egress, Ingress
@@ -85,6 +108,30 @@ func (q *Queries) GetDnsBlackList(ctx context.Context) ([]string, error) {
return items, nil
}
+const getMacBlackList = `-- name: GetMacBlackList :many
+SELECT hardwareaddr FROM MacBlackList
+`
+
+func (q *Queries) GetMacBlackList(ctx context.Context) ([]int64, error) {
+ rows, err := q.db.Query(ctx, getMacBlackList)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []int64
+ for rows.Next() {
+ var hardwareaddr int64
+ if err := rows.Scan(&hardwareaddr); err != nil {
+ return nil, err
+ }
+ items = append(items, hardwareaddr)
+ }
+ 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
`
diff --git a/db/schema.sql b/db/schema.sql
index c8c35a1..78668c6 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -9,3 +9,7 @@ CREATE TABLE IF NOT EXISTS Usage (
CREATE TABLE IF NOT EXISTS DnsBlackList (
Name TEXT NOT NULL UNIQUE
);
+
+CREATE TABLE IF NOT EXISTS MacBlackList (
+ HardwareAddr BIGINT NOT NULL UNIQUE
+);