SurrealDB
SurrealDB Docs Logo

Enter a search query

Navigation

API Reference

Data Types

Data Types

The JavaScript SDK provides custom classes for SurrealDB-specific data types, ensuring type safety and data integrity when working with the database. For a conceptual overview with usage examples and best practices, see the Value types concept page.

Custom Data Type Classes

  • RecordId - Type-safe record identifiers with table and ID components

    • new RecordId(table, id) - Create record ID
    • RecordId.parse(string) - Parse from string
    • Also includes RecordIdRange for querying ranges
  • Table - Type-safe table references

    • new Table<T>(name) - Create typed table reference
    • Used in SELECT, CREATE, UPDATE, DELETE operations
  • DateTime - Datetime values with nanosecond precision

    • DateTime.now() - Current datetime
    • DateTime.parse(string) - Parse from ISO string
    • .toDate() - Convert to JavaScript Date
  • Duration - Time duration with support for multiple units

    • Duration.parse('5h30m') - Parse from string
    • .toMilliseconds() - Convert to milliseconds
  • Decimal - Arbitrary precision decimal numbers

    • new Decimal('19.99') - Create precise decimal
    • Preserves precision during operations
  • Uuid - Universally unique identifiers

    • Uuid.v4() - Generate random UUID
    • Uuid.v7() - Generate time-ordered UUID
  • Range - Generic range values for numeric and date ranges

  • FileRef - References to files stored in SurrealDB

    • .bucket - Storage bucket name
    • .key - File key within the bucket

Geometric Types

  • Geometry - Spatial/geometric data types
    • GeometryPoint - Single point
    • GeometryLine - Line between points
    • GeometryPolygon - Polygon shape
    • GeometryMultiPoint, GeometryMultiLine, GeometryMultiPolygon
    • GeometryCollection - Mixed geometry collection

See Also