The PostGIS extension pack adds theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/prisma/prisma-next/llms.txt
Use this file to discover all available pages before exploring further.
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
Geometrycolumn 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/geojsonhandle 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 declarespostgisas a database dependency, soprisma-next db initinstalls it before the first migration runs. - Capability flag — declares
postgis.geometryto 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 thepostgis/postgis Docker image or imresamu/postgis on Apple Silicon hosts.
Setup
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.Emit the contract and initialize the database
db init runs CREATE EXTENSION postgis before any application migration.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.
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.
Operations reference
| Method | SQL | Returns | Use when |
|---|---|---|---|
distance(other) | ST_Distance(self, other) | float8 | Cartesian distance in the geometry’s native units (degrees for SRID 4326). |
distanceSphere(other) | ST_DistanceSphere(self, other) | float8 | Sphere-accurate metres between two lng/lat geometries. |
dwithin(other, distance) | ST_DWithin(self, other, distance) | boolean | Index-friendly “within X distance” check. Distance is in the geometry’s native units. |
contains(other) | ST_Contains(self, other) | boolean | Point-in-polygon and polygon-contains-polygon checks. |
within(other) | ST_Within(self, other) | boolean | Inverse of contains — A within B is equivalent to B contains A. |
intersects(other) | ST_Intersects(self, other) | boolean | Any kind of overlap between two geometries. |
intersectsBbox(other) | self && other | boolean | Cheap 2-D bounding-box overlap — fast viewport filtering. |
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)orgeometry({ srid: 4326 })) to constrain the column and have the runtime preserve the SRID through writes. - The
point,polygon, andbboxPolygonconstructors attach the SRID to the value. The codec emits it asSRID=4326;…EWKT on the wire. distanceanddwithinare not unit-aware. PreferdistanceSpherefor 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-postgresreturns 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 declarespostgis.geometry. Features that require PostGIS geometry support can declare a requires: ['postgis.geometry'] constraint in their capability gate.