diff options
Diffstat (limited to 'connector.go')
| -rw-r--r-- | connector.go | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/connector.go b/connector.go index d7f1242..1914ddb 100644 --- a/connector.go +++ b/connector.go @@ -1,13 +1,28 @@ // SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net> // SPDX-License-Identifier: Apache-2.0 -// Package gg_pgx contains integration for using [gg/gsql] (and libraries based on it, such as [Oblast]) with the PostgreSQL driver library [pgx]. -// -// [gg/gsql]: https://pkg.go.dev/go.xyrillian.de/gg/gsql -// [Oblast]: https://pkg.go.dev/go.xyrillian.de/oblast -// [pgx]: https://github.com/jackc/pgx package gg_pgx -// TODO: implement Handle (handle.go is copied from an early prototype in the Oblast benchmark suite and uses the extremely old Wrap() style) -// TODO: implement ConnectionHandle -// TODO: test coverage (via gg/pgruntime) +import ( + "context" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + "go.xyrillian.de/gg/pgruntime" +) + +// SingleConnector returns a [pgruntime.Connector] that spawns individual database connections. +func SingleConnector() pgruntime.Connector[*Conn] { + return func(ctx context.Context, dbURL string) (*Conn, error) { + conn, err := pgx.Connect(ctx, dbURL) + return maybe(NewConn, conn), err + } +} + +// PoolConnector returns a [pgruntime.Connector] that spawns database connection pools. +func PoolConnector() pgruntime.Connector[*Pool] { + return func(ctx context.Context, dbURL string) (*Pool, error) { + pool, err := pgxpool.New(ctx, dbURL) + return maybe(NewPool, pool), err + } +} |
