Skip to main content
The PostGIS extension pack adds the geometry column type and seven spatial query operations to Prisma Next for PostgreSQL databases. You store points, linestrings, polygons, and their multi-geometry variants as GeoJSON-shaped values, attach an optional SRID (e.g. 4326 for WGS84 lng/lat), and query them with distance, containment, and intersection operations — all without learning PostGIS-specific client APIs.

What the extension provides

  • Geometry column type — stores Points, LineStrings, Polygons, and their Multi-* variants. Accepts an optional SRID parameter (Geometry(4326) for WGS84 lng/lat).
  • GeoJSON-shaped runtime values — read and write geometries as plain { type, coordinates, srid? } objects. Constructors from @prisma-next/extension-postgis/geojson handle coordinate ordering and SRID metadata.
  • Seven query operations — distance, distanceSphere, dwithin, contains, within, intersects, intersectsBbox — available in .where(), .select(), and .orderBy().
  • Automatic CREATE EXTENSION — the control descriptor declares postgis as a database dependency, so prisma-next db init installs it before the first migration runs.
  • Capability flag — declares postgis.geometry to gate the codec and all seven operations.

Prerequisites

The PostGIS extension must be available on your PostgreSQL server. Most managed providers (RDS, Cloud SQL, Supabase, Neon) include it. For local development, use the postgis/postgis Docker image or imresamu/postgis on Apple Silicon hosts.

Setup

1

Install the package

2

Register the extension in prisma-next.config.ts

prisma-next.config.ts
3

Declare geometry columns in your schema

Use postgis.Geometry(srid) in PSL or the TypeScript contract builder.
postgis.Geometry(srid) and geometry({ srid }) are the SRID-constrained forms — they emit geometry(Geometry, 4326) in DDL. Use postgis.Geometry() or geometryColumn for schemas that mix SRIDs at the row level.
4

Emit the contract and initialize the database

db init runs CREATE EXTENSION postgis before any application migration.
5

Wire the extension into the runtime

src/prisma/db.ts

Building geometry values

Use the constructors from @prisma-next/extension-postgis/geojson to build geometry values. They handle coordinate ordering ([lng, lat]) and SRID metadata.
For LineString, MultiPoint, MultiLineString, and MultiPolygon, construct the object directly:

Querying

All seven operations are available inside .where(), .select(), and .orderBy() callbacks via the fns argument.
User-supplied geometries (the second argument to each operation) are bound as parameters — not interpolated. The codec encodes them as EWKT on the wire.

Operations reference

Picking the right distance operation

For SRID 4326 (WGS84) lng/lat data, distance returns degrees, which is rarely what you want. Use distanceSphere to get human-friendly metres. dwithin interprets its distance argument in whatever units the inputs use — pair it with a projected SRS if you need metres directly.

SRID and units

  • Declare an SRID at the column level (postgis.Geometry(4326) or geometry({ srid: 4326 })) to constrain the column and have the runtime preserve the SRID through writes.
  • The point, polygon, and bboxPolygon constructors attach the SRID to the value. The codec emits it as SRID=4326;… EWKT on the wire.
  • distance and dwithin are not unit-aware. Prefer distanceSphere for WGS84 metre-based comparisons.

Wire format

  • JS → SQL: geometries are emitted as EWKT (SRID=4326;POINT(-122.39 37.79)) and cast to ::geometry.
  • SQL → JS: node-postgres returns geometry columns as hex-encoded EWKB. The codec parses Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon.
Z and M coordinates are not supported in this release. If a geometry column carries them, decoding throws so the mismatch is visible rather than silent.

Types

Capability flag

The extension declares postgis.geometry. Features that require PostGIS geometry support can declare a requires: ['postgis.geometry'] constraint in their capability gate.