add db.Pool

This commit is contained in:
nate smith 2024-04-30 21:19:19 -07:00
parent cba908d1fd
commit 25147572f8
2 changed files with 14 additions and 2 deletions

View File

@ -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

2
go.mod
View File

@ -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