Skip to content

Commit

Permalink
fix: register geos codecs in postgis example main.go (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: sebdotv <sebdotv@gmail.com>
  • Loading branch information
sebdotv and sebdotv authored Aug 13, 2024
1 parent 04dbb3e commit b84b56f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 9 additions & 0 deletions examples/postgis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
pgxgeos "github.com/twpayne/pgx-geos"
"io"
"os"

Expand Down Expand Up @@ -61,6 +62,11 @@ func (w *Waypoint) UnmarshalJSON(data []byte) error {
return nil
}

// registerGeos registers required codecs
func registerGeos(ctx context.Context, conn *pgx.Conn) error {
return pgxgeos.Register(ctx, conn, geos.NewContext())
}

// createDB demonstrates create a PostgreSQL/PostGIS database with a table with
// a geometry column.
func createDB(ctx context.Context, conn *pgx.Conn) error {
Expand Down Expand Up @@ -165,6 +171,9 @@ func run() error {
}
}
if *write {
if err := registerGeos(ctx, conn); err != nil {
return err
}
if err := writeGeoJSON(ctx, conn, os.Stdout); err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions examples/postgis/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/postgres"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/twpayne/go-geos"
pgxgeos "github.com/twpayne/pgx-geos"
)

func TestIntegration(t *testing.T) {
Expand Down Expand Up @@ -54,7 +52,7 @@ func TestIntegration(t *testing.T) {

conn, err := pgx.Connect(ctx, connStr)
assert.NoError(t, err)
assert.NoError(t, pgxgeos.Register(ctx, conn, geos.NewContext()))
assert.NoError(t, registerGeos(ctx, conn))

assert.NoError(t, createDB(ctx, conn))

Expand Down

0 comments on commit b84b56f

Please sign in to comment.