Geospatial Data
SurrealDB can store and query GeoJSON-like geometry. UnrealORM provides Field.geometry(...) with a typed GeometryType.
Geometry types
Section titled “Geometry types”import { Table, Field } from 'unreal-orm';
class Place extends Table.normal({ name: 'place', schemafull: true, fields: { name: Field.string(), location: Field.geometry('point'), boundary: Field.geometry('polygon'), route: Field.geometry('linestring'), },}) {}Supported types: point, linestring, polygon, multipoint, multilinestring, multipolygon, collection, and feature.
Inserting geometry
Section titled “Inserting geometry”Use surrealdb geometry helpers or raw values:
await Place.create(db, { name: 'Office', location: { type: 'Point', coordinates: [-0.1276, 51.5074] },});Spatial queries
Section titled “Spatial queries”Use surql for distance, intersection, and containment checks:
const nearby = await Place.select(db, { where: surql`geo::distance(location, { type: 'Point', coordinates: [-0.1276, 51.5074] }) < 10_000`,});The where builder also exposes intersects when you are comparing geometry columns:
Place.select(db, { where: (f) => f.boundary.intersects(area),});For advanced spatial operations, write the expression directly in surql.