File tree 1 file changed +65
-0
lines changed
1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -208,6 +208,71 @@ type Book struct {
208
208
209
209
### PostGIS
210
210
211
+ #### Using ` github.com/twpayne/go-geos ` (pgx/v5 only)
212
+
213
+ sqlc can be configured to use the [ geos] ( https://github.com/twpayne/go-geos )
214
+ package for working with PostGIS geometry types in [ GEOS] ( https://libgeos.org/ ) .
215
+
216
+ There are three steps:
217
+
218
+ 1 . Configure sqlc to use ` *github.com/twpayne/go-geos.Geom ` for geometry types.
219
+ 2 . Call ` github.com/twpayne/pgx-geos.Register ` on each
220
+ ` *github.com/jackc/pgx/v5.Conn ` .
221
+ 3 . Annotate your SQL with ` ::geometry ` typecasts, if needed.
222
+
223
+ ``` sql
224
+ -- Multipolygons in British National Grid (epsg:27700)
225
+ create table shapes (
226
+ id serial ,
227
+ name varchar ,
228
+ geom geometry(Multipolygon, 27700 )
229
+ );
230
+
231
+ -- name: GetCentroids :many
232
+ SELECT id, name, ST_Centriod(geom)::geometry FROM shapes;
233
+ ```
234
+
235
+ ``` json
236
+ {
237
+ "version" : 2 ,
238
+ "gen" : {
239
+ "go" : {
240
+ "overrides" : [
241
+ {
242
+ "db_type" : " geometry" ,
243
+ "go_type" : {
244
+ "import" : " github.com/twpayne/go-geos" ,
245
+ "package" : " geos" ,
246
+ "pointer" : true ,
247
+ "type" : " Geom"
248
+ },
249
+ "nullable" : true
250
+ }
251
+ ]
252
+ }
253
+ }
254
+ }
255
+ ```
256
+
257
+ ``` go
258
+ import (
259
+ " github.com/twpayne/go-geos"
260
+ pgxgeos " github.com/twpayne/pgx-geos"
261
+ )
262
+
263
+ // ...
264
+
265
+ config.AfterConnect = func (ctx context.Context , conn *pgx.Conn ) error {
266
+ if err := pgxgeos.Register (ctx, conn, geos.NewContext ()); err != nil {
267
+ return err
268
+ }
269
+ return nil
270
+ }
271
+ ```
272
+
273
+
274
+ #### Using ` github.com/twpayne/go-geom `
275
+
211
276
sqlc can be configured to use the [ geom] ( https://github.com/twpayne/go-geom )
212
277
package for working with PostGIS geometry types.
213
278
You can’t perform that action at this time.
0 commit comments