From 25147572f8192ad15af9ecefd844f28f89470062 Mon Sep 17 00:00:00 2001 From: nate smith Date: Tue, 30 Apr 2024 21:19:19 -0700 Subject: [PATCH] add db.Pool --- db/db.go | 14 ++++++++++++-- go.mod | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/db/db.go b/db/db.go index 709d8e4..5aa3853 100644 --- a/db/db.go +++ b/db/db.go @@ -6,12 +6,13 @@ import ( "fmt" "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" ) const ( + // TODO unused; i think i failed to make this work. should i just rely on the env + // vars like i've been doing? dburl = "postgresql://vilmibm/postgres?host=/home/vilmibm/src/trunkless/pgdata/sockets" - // MaxID = 467014991 - MaxID = 345507789 ) func StrToID(s string) string { @@ -27,4 +28,13 @@ func Connect() (*pgx.Conn, error) { return conn, nil } +func Pool() (*pgxpool.Pool, error) { + pool, err := pgxpool.New(context.Background(), "") + if err != nil { + return nil, fmt.Errorf("Unable to connect to database: %w", err) + } + + return pool, nil +} + // TODO func for getting ID ranges for each corpus in phrases diff --git a/go.mod b/go.mod index 90e2024..d8fc576 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/kr/text v0.2.0 // indirect @@ -35,6 +36,7 @@ require ( golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.17.0 // indirect golang.org/x/net v0.10.0 // indirect + golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/protobuf v1.30.0 // indirect