Skip to content

Commit

Permalink
docs: add examples to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 1, 2024
1 parent 81785d5 commit 70a09a3
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,59 @@ Package pgx-geos provides [PostGIS](https://postgis.net/) and
[`github.com/jackc/pgx/v5`](https://pkg.go.dev/github.com/jackc/pgx/v5) via
[`*github.com/twpayne/go-geos.Geom`](https://pkg.go.dev/github.com/twpayne/go-geos#Geom).

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

0 comments on commit 70a09a3

Please sign in to comment.