Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 SDK. For use with version 1.x, see here.

Geospatial Data

SurrealDB can store and query GeoJSON-like geometry. UnrealORM provides Field.geometry(...) with a typed GeometryType.

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.

Use surrealdb geometry helpers or raw values:

await Place.create(db, {
name: 'Office',
location: { type: 'Point', coordinates: [-0.1276, 51.5074] },
});

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.