blob: 1914ddb0d21c1cba9e75019ada790756978306f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
// SPDX-License-Identifier: Apache-2.0
package gg_pgx
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
}
}
|