Skip to content

Spatial Queries (PostGIS)

Find records within a radius:

const nearby = await pulsabase.from(Restaurant)
.where('location', {
$near: { type: 'Point', coordinates: [2.3522, 48.8566], maxDistanceKm: 5 }
})
.sort('distance', 'asc')
.find();
const inArea = await pulsabase.from(Store)
.where('location', {
$within: { type: 'Box', coordinates: [[2.2, 48.8], [2.5, 48.9]] }
})
.find();
pulsabase.from('zones')
.where('area', intersects(myGeoJsonPolygon))
.find();

Add a computed distance column:

pulsabase.from('restaurants')
.selectDistance('location', lat: 48.85, lng: 2.35, alias: 'distance_km')
.sort('distance_km', 'asc')
.find();