Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/twpayne/pgx-geos

Package pgx-geos provides PostGIS and GEOS support for github.com/jackc/pgx/v5 via github.com/twpayne/go-geos.
https://github.com/twpayne/pgx-geos

geospatial gis go golang postgis postgres postgresql wkb wkt

Last synced: 12 days ago
JSON representation

Package pgx-geos provides PostGIS and GEOS support for github.com/jackc/pgx/v5 via github.com/twpayne/go-geos.

Awesome Lists containing this project

README

        

# pgx-geos

[![PkgGoDev](https://pkg.go.dev/badge/github.com/twpayne/pgx-geos)](https://pkg.go.dev/github.com/twpayne/pgx-geos)

Package pgx-geos provides [PostGIS](https://postgis.net/) and
[GEOS](https://libgeos.org/) support for
[`github.com/jackc/pgx/v5`](https://pkg.go.dev/github.com/jackc/pgx/v5) via
[`github.com/twpayne/go-geos`](https://pkg.go.dev/github.com/twpayne/go-geos).

## Usage

### Single connection

```go
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
}
```

### Connection pool

```go
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
}
```

## License

MIT