Package pgx-geos provides PostGIS and
GEOS support for
github.com/jackc/pgx/v5
via
github.com/twpayne/go-geos
.
import (
// ...
"github.com/jackc/pgx/v5"
"github.com/twpayne/go-geos"
pgxgeos "github.com/twpayne/pgx-geos"
)
// ...
connectionStr := os.Getenv("DATABASE_URL")
conn, err := pgx.Connect(context.Background(), connectionStr)
if err != nil {
return err
}
if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil {
return err
}
import (
// ...
"github.com/jackc/pgx/v5/pgxpool"
)
// ...
config, err := pgxpool.ParseConfig(connectionStr)
if err != nil {
return err
}
config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
if err := pgxgeos.Register(ctx, conn, geos.NewContext()); err != nil {
return err
}
return nil
}
pool, err := pgxpool.NewWithConfig(context.Background(), config)
if err != nil {
return err
}
MIT