The Go SDK maps most SurrealDB values onto Go's own types, such as string, bool, int64, time.Time and map[string]any. Go has no type for some values, such as record IDs, geometry and the SurrealDB 4.0 kinds. For these values, the SDK has types in the models package, and this section has a page for each type. This page lists the types and maps each SurrealDB type onto its Go type. For a guide to how values convert, with examples, see Value types.
import "github.com/surrealdb/surrealdb.go/v2/pkg/models"Value types
CustomDateTime:
CustomDateTimewrapstime.Timefor a datetime. The SDK also sends atime.Timeas a datetime.CustomDuration:
CustomDurationwrapstime.Durationfor a duration. The SDK also sends atime.Durationas a duration.Geometry:
GeometryPointand six other types for GeoJSON geometry.Range:
RangewithBoundIncludedandBoundExcluded, for a span of values or of record IDs.RecordID:
RecordIDnames one record by its table and ID.Table:
Tablenames a table.UUID:
UUIDholds a UUID.Set:
Setholds the distinct values of a set.Numbers:
Float16,DecimalStringandBigDecimal, and the Go types for the sized numbers of SurrealDB 4.0.Dates, times and intervals:
PlainDate,PlainTime,TimestampandInterval, for the calendar kinds of SurrealDB 4.0.Regex:
Regexholds a pattern for theregexkind of SurrealDB 4.0.File:
Filepoints to a file in a bucket.
Type mapping
| SurrealDB | Go | Page |
|---|---|---|
NONE | models.None to send; nil when decoded | Value types |
NULL | nil | Value types |
bool | bool | |
int | int, int64, and the other integer types | Numbers |
float | float64 | Numbers |
decimal | models.DecimalString | Numbers |
string | string | |
bytes | []byte | |
datetime | time.Time, models.CustomDateTime | CustomDateTime |
duration | time.Duration, models.CustomDuration | CustomDuration |
uuid | models.UUID | UUID |
record | models.RecordID | RecordID |
table | models.Table | Table |
array | []any or a typed slice | |
object | map[string]any or a struct | |
set | models.Set | Set |
range | models.Range | Range |
geometry | models.GeometryPoint and the other geometry types | Geometry |
file | models.File | File |
i8, u8, i16, u16, i32, u32, u64 | int8, uint8, int16, uint16, int32, uint32, uint64 | Numbers |
f16, f32 | models.Float16, float32 | Numbers |
bigdecimal | models.BigDecimal | Numbers |
date, time, timestamp, interval | models.PlainDate, PlainTime, Timestamp, Interval | Dates, times and intervals |
regex | models.Regex | Regex |
The SurrealDB 4.0 kinds, from i8 to regex, keep their type over cbor.2 only. With a server before 4.0, the SDK and the server send them as the nearest older kind, as Value types describes.
See also
Value types for how values convert, with examples
SurrealQL data types for the type system of SurrealDB