SurrealDB has types that JavaScript does not: record IDs, nanosecond datetimes, arbitrary-precision decimals, and others. They live in @surrealdb/sqon, which also ships codecs and a few core utilities. The surrealdb package re-exports all of it, so either import path works:
The classes validate input, keep database precision, and plug into query methods and codecs.
API references
| Class | Description |
|---|---|
RecordId | Type-safe record identifiers with table and ID components |
Table | Type-safe table references for query methods |
DateTime | Datetime values with nanosecond precision |
Duration | Time duration values with multiple unit support |
Decimal | Arbitrary precision decimal numbers |
Uuid | Universally unique identifiers (v4 and v7) |
Range | Bounded or unbounded range values |
FileRef | References to files stored in SurrealDB |
Geometry* | GeoJSON geometry types (Point, Line, Polygon, etc.) |
Type mapping
SurrealQL types map to JavaScript types as follows:
| SurrealQL type | JavaScript type | Example |
|---|---|---|
bool | boolean | true, false |
int, float | number | 42, 3.14 |
string | string | "hello" |
null | null | null |
none | undefined | undefined |
array | Array | [1, 2, 3] |
object | Object | {`{ key: "value" }`} |
set | Set | new Set([1, 2, 3]) |
bytes | Uint8Array | new Uint8Array([...]) |
record | RecordId | new RecordId('users', 'john') |
| - | Table | new Table('users') |
datetime | DateTime | DateTime.now() |
duration | Duration | Duration.parse('1h30m') |
decimal | Decimal | new Decimal('19.99') |
uuid | Uuid | Uuid.v7() |
geometry | Geometry* | new GeometryPoint([1, 2]) |
range | Range | new Range(1, 10) |
file | FileRef | record.avatar |
RecordId and Table
A RecordId is a table name plus an ID. A Table is a table reference on its own. From v2 onward, query methods expect a Table instance for table names, not a bare string, so table names are not confused with record IDs.
The ID component of a RecordId can be a string, number, bigint, Uuid, array, or object. The Table class also supports a type parameter for type-safe query results.
DateTime and Duration
A DateTime is a timestamp with nanosecond precision. JavaScript's Date stops at milliseconds, so DateTime keeps what SurrealDB actually stored. A Duration follows SurrealQL duration syntax.
Decimal
A Decimal holds a decimal without floating-point rounding. Construct it from a string when precision matters.
Note
Uuid
A Uuid represents a universally unique identifier. The class supports generating both v4 (random) and v7 (time-ordered) UUIDs.
Range
A Range is a bounded or open-ended span of values. In SurrealQL you use ranges to slice record IDs or filter numbers and times. RecordIdRange is the variant for a table ID range.
FileRef
A FileRef points at a file stored in SurrealDB. You see one when working with file uploads; it carries bucket and key metadata.
Geometry types
The SDK provides classes for all GeoJSON geometry types: GeometryPoint, GeometryLine, GeometryPolygon, GeometryMultiPoint, GeometryMultiLine, GeometryMultiPolygon, and GeometryCollection.
Parsing from strings
Most classes accept the same string forms as SurrealQL. Invalid input throws.
Using native dates
By default, datetimes come back as DateTime. Set useNativeDates in codec options if you would rather work with Date and can accept millisecond precision.
String prefixes
The surrealdb package includes tagged templates that mirror SurrealQL's s, d, r, and u prefixes. They are not part of @surrealdb/sqon.
Best practices
Use type parameters for type-safe queries
Prefer value classes over raw strings
Validate parsed input
Learn more
Data Types API reference for the full list of value class documentation
Codecs for serialising and deserialising value types
SurrealQL data model for the database-level type system
Utilities for comparing and converting values