Spatial Queries (PostGIS)
Near Point
Section titled “Near Point”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();final nearby = await pulsabase.from('restaurants') .where('location', nearPoint(lat: 48.8566, lng: 2.3522, radiusKm: 5)) .selectDistance('location', lat: 48.8566, lng: 2.3522) .sort('distance', 'asc') .find();Within Bounding Box
Section titled “Within Bounding Box”const inArea = await pulsabase.from(Store) .where('location', { $within: { type: 'Box', coordinates: [[2.2, 48.8], [2.5, 48.9]] } }) .find();final inArea = await pulsabase.from('stores') .where('location', withinBox( minLat: 48.8, minLng: 2.2, maxLat: 48.9, maxLng: 2.5, )) .find();Intersects
Section titled “Intersects”pulsabase.from('zones') .where('area', intersects(myGeoJsonPolygon)) .find();Distance Calculation
Section titled “Distance Calculation”Add a computed distance column:
pulsabase.from('restaurants') .selectDistance('location', lat: 48.85, lng: 2.35, alias: 'distance_km') .sort('distance_km', 'asc') .find();