aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-31 16:59:18 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-31 16:59:18 +0800
commit655b6b211ae6df0186abd740f248939f7ddeaec1 (patch)
treeec5cdbbc52222f62c8fbb0bcf2a1aa7a9f6eb8b6 /database.go
parentCorrect table headers in MR indices (diff)
downloadforge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.gz
forge-655b6b211ae6df0186abd740f248939f7ddeaec1.tar.zst
forge-655b6b211ae6df0186abd740f248939f7ddeaec1.zip
Add descriptive comments to most Go functions
Diffstat (limited to 'database.go')
-rw-r--r--database.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/database.go b/database.go
index 5205214..87fa9f4 100644
--- a/database.go
+++ b/database.go
@@ -7,10 +7,23 @@ import (
"context"
"github.com/jackc/pgx/v5"
+ "github.com/jackc/pgx/v5/pgxpool"
)
+// TODO: All database handling logic in all request handlers must be revamped.
+// We must ensure that each request has all logic in one transaction (subject
+// to exceptions if appropriate) so they get a consistent view of the database
+// at a single point. A failure to do so may cause things as serious as
+// privilege escalation.
+
+// database serves as the primary database handle for this entire application.
+// Transactions or single reads may be used therefrom. A [pgxpool.Pool] is
+// necessary to safely use pgx concurrently; pgx.Conn, etc. are insufficient.
+var database *pgxpool.Pool
+
// queryNameDesc is a helper function that executes a query and returns a
-// list of name_desc_t results.
+// list of nameDesc results. The query must return two string arguments, i.e. a
+// name and a description.
func queryNameDesc(ctx context.Context, query string, args ...any) (result []nameDesc, err error) {
var rows pgx.Rows