githubEdit

Types Reference

This section provides comprehensive documentation for all field types supported by SOM. Each type includes its Go definition, SurrealDB schema, available filter operations, sorting capabilities, and practical examples.

Quick Reference

Type
Go Type
DB Schema
CBOR
Sortable
Filters

string

string

Direct

Yes

50+

int, float64, etc.

int / float

Direct

Yes

20+

bool

bool

Direct

Yes

4

byte / []byte

int / bytes

Direct

Yes/No

8+

time.Time

datetime

Tag 12

Yes

25+

time.Duration

duration

Tag 14

Yes

15+

uuid.UUID

uuid

Tag 37

Yes

8

url.URL

string

Direct

Yes

15+

som.Email

string

Direct

Yes

10+

Custom type

String union

Direct

Yes

8

[]T

array<T>

Direct

No

30+

*OtherNode

record<table>

Direct

No

Via fields

Embedded struct

object

Direct

No

Via fields

Type Categories

Primitive Types

Basic Go types with direct database mapping:

  • String - Text data with extensive string operations

  • Numeric - Integers and floating-point numbers

  • Bool - Boolean true/false values

  • Byte - Single bytes and binary data

Time Types

Temporal data with special CBOR encoding:

  • Time - Timestamps using time.Time

  • Duration - Time intervals using time.Duration

Special Types

Types with validation or special handling:

  • UUID - Universally unique identifiers

  • URL - Web addresses with component parsing

  • Email - Email addresses with validation

  • Enum - Constrained string values

Complex Types

Composite and reference types:

  • Slice - Arrays of any type

  • Node - References to other records

  • Struct - Nested object structures

Universal Operations

All types support these base filter operations:

Pointer Types (Optional Fields)

All types support pointer variants for optional fields:

Pointer types add nil-checking operations:

CBOR Encoding

SOM uses CBOR (Concise Binary Object Representation) for efficient database communication. Most types use direct CBOR encoding, but some require special handling:

Type
CBOR Tag
Format

DateTime

12

[unix_seconds, nanoseconds]

Duration

14

[seconds, nanoseconds]

UUID

37

Binary (16 bytes)

Sorting

Most types support ascending and descending sort:

Not sortable: Slice, Node, Struct (use nested field sorting instead)

Method Chaining

Many filter operations return new filters, enabling powerful chains:

Schema Generation

SOM generates SurrealDB schema definitions for each field:

Last updated