# Data types

Type mapping between SurrealQL and JavaScript, and custom data type classes.

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](/docs/reference/javascript/concepts/value-types.md).

## Custom data type classes

- [**RecordId**](/docs/reference/javascript/api/values/record-id.md) - Type-safe record identifiers with table and ID components
  - `new RecordId(table, id)` - Create record ID
  - Also includes `RecordIdRange` for querying ranges

- [**Table**](/docs/reference/javascript/api/values/table.md) - Type-safe table references
  - `new Table<T>(name)` - Create typed table reference
  - Used in SELECT, CREATE, UPDATE, DELETE operations

- [**DateTime**](/docs/reference/javascript/api/values/datetime.md) - Datetime values with nanosecond precision
  - `DateTime.now()` - Current datetime
  - `new DateTime(string)` - Parse from ISO string
  - `.toDate()` - Convert to JavaScript Date

- [**Duration**](/docs/reference/javascript/api/values/duration.md) - Time duration with support for multiple units
  - `new Duration('5h30m')` - Parse from string
  - `.milliseconds` - Get duration in milliseconds

- [**Decimal**](/docs/reference/javascript/api/values/decimal.md) - Arbitrary precision decimal numbers
  - `new Decimal('19.99')` - Create precise decimal
  - Preserves precision during operations

- [**Uuid**](/docs/reference/javascript/api/values/uuid.md) - Universally unique identifiers
  - `Uuid.v4()` - Generate random UUID
  - `Uuid.v7()` - Generate time-ordered UUID

- [**Range**](/docs/reference/javascript/api/values/range.md) - Generic range values for numeric and date ranges

- [**FileRef**](/docs/reference/javascript/api/values/file-ref.md) - References to files stored in SurrealDB
  - `.bucket` - Storage bucket name
  - `.key` - File key within the bucket

## Geometric types

- [**Geometry**](/docs/reference/javascript/api/values/geometry.md) - Spatial/geometric data types
  - `GeometryPoint` - Single point
  - `GeometryLine` - Line between points
  - `GeometryPolygon` - Polygon shape
  - `GeometryMultiPoint`, `GeometryMultiLine`, `GeometryMultiPolygon`
  - `GeometryCollection` - Mixed geometry collection

## See also

- [Value types concept page](/docs/reference/javascript/concepts/value-types.md) - Usage guide with type mapping, examples, and best practices
- [SurrealQL data types](/docs/reference/query-language/language-primitives/data-types.md) - Database data model
- [Utilities](/docs/reference/javascript/concepts/utilities.md) - Comparing and converting values
