Skip to content

API Reference

/

Values

Go values

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
import "github.com/surrealdb/surrealdb.go/v2/pkg/models"
  • CustomDateTime: CustomDateTime wraps time.Time for a datetime. The SDK also sends a time.Time as a datetime.

  • CustomDuration: CustomDuration wraps time.Duration for a duration. The SDK also sends a time.Duration as a duration.

  • Geometry: GeometryPoint and six other types for GeoJSON geometry.

  • Range: Range with BoundIncluded and BoundExcluded, for a span of values or of record IDs.

  • RecordID: RecordID names one record by its table and ID.

  • Table: Table names a table.

  • UUID: UUID holds a UUID.

  • Set: Set holds the distinct values of a set.

  • Numbers: Float16, DecimalString and BigDecimal, and the Go types for the sized numbers of SurrealDB 4.0.

  • Dates, times and intervals: PlainDate, PlainTime, Timestamp and Interval, for the calendar kinds of SurrealDB 4.0.

  • Regex: Regex holds a pattern for the regex kind of SurrealDB 4.0.

  • File: File points to a file in a bucket.

SurrealDBGoPage
NONEmodels.None to send; nil when decodedValue types
NULLnilValue types
boolbool
intint, int64, and the other integer typesNumbers
floatfloat64Numbers
decimalmodels.DecimalStringNumbers
stringstring
bytes[]byte
datetimetime.Time, models.CustomDateTimeCustomDateTime
durationtime.Duration, models.CustomDurationCustomDuration
uuidmodels.UUIDUUID
recordmodels.RecordIDRecordID
tablemodels.TableTable
array[]any or a typed slice
objectmap[string]any or a struct
setmodels.SetSet
rangemodels.RangeRange
geometrymodels.GeometryPoint and the other geometry typesGeometry
filemodels.FileFile
i8, u8, i16, u16, i32, u32, u64int8, uint8, int16, uint16, int32, uint32, uint64Numbers
f16, f32models.Float16, float32Numbers
bigdecimalmodels.BigDecimalNumbers
date, time, timestamp, intervalmodels.PlainDate, PlainTime, Timestamp, IntervalDates, times and intervals
regexmodels.RegexRegex

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.

Was this page helpful?