summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/query.sql3
-rw-r--r--db/query.sql.go16
2 files changed, 19 insertions, 0 deletions
diff --git a/db/query.sql b/db/query.sql
index 75d5b61..cfea3f1 100644
--- a/db/query.sql
+++ b/db/query.sql
@@ -4,3 +4,6 @@ INSERT INTO Usage (
) VALUES (
$1, $2, $3, $4, $5
);
+
+-- name: GetUsage :one
+SELECT SUM(Ingress) AS Ingress, SUM(Egress) AS Egress FROM Usage;
diff --git a/db/query.sql.go b/db/query.sql.go
index 7afe159..d6304a7 100644
--- a/db/query.sql.go
+++ b/db/query.sql.go
@@ -37,3 +37,19 @@ func (q *Queries) EnterUsage(ctx context.Context, arg EnterUsageParams) error {
)
return err
}
+
+const getUsage = `-- name: GetUsage :one
+SELECT SUM(Ingress) AS Ingress, SUM(Egress) AS Egress FROM Usage
+`
+
+type GetUsageRow struct {
+ Ingress int64
+ Egress int64
+}
+
+func (q *Queries) GetUsage(ctx context.Context) (GetUsageRow, error) {
+ row := q.db.QueryRow(ctx, getUsage)
+ var i GetUsageRow
+ err := row.Scan(&i.Ingress, &i.Egress)
+ return i, err
+}