SurrealDB Docs Logo

Enter a search query

Data Types

This SDK facilitates communication between client and the backend service using the Concise Binary Object Representation (CBOR) format. It streamlines data serialization and deserialization while ensuring efficient and lightweight communication. The library also provides custom models tailored to specific Data models recognised by SurrealDb, which cannot be covered by idiomatic Go, enabling seamless interaction between the client and the backend.

Data Types overview

CBOR TypeGo RepresentationExample
Nullnilvar x interface{} = nil
Nonesurrealdb.Nonemap[string]interface{}{"customer": surrealdb.None}
Booleanbooltrue, false
Array[]interface{}[]MyStruct{item1, item2}
Date/Timetime.Timetime.Now()
Durationtime.Durationtime.Duration(8821356)
UUID (string representation)surrealdb.UUID(string)surrealdb.UUID("123e4567-e89b-12d3-a456-426614174000")
UUID (binary representation)surrealdb.UUIDBin([]bytes)surrealdb.UUIDBin([]byte{0x01, 0x02, ...})`
Integeruint, uint64, int, int6442, uint64(100000), -42, int64(-100000)
Floating Pointfloat32, float643.14, float64(2.71828)
Byte String, Binary Encoded Data[]byte[]byte{0x01, 0x02}
Text Stringstring"Hello, World!"
Mapmap[interface{}]interface{}map[string]float64{"one": 1.0}
Table namesurrealdb.Table(name)surrealdb.Table("users")
Record IDsurrealdb.RecordID{Table: string, ID: interface{}}surrealdb.RecordID{Table: "customers", ID: 1}, surrealdb.NewRecordID("customers", 1)
Geometry Pointsurrealdb.GeometryPoint{Latitude: float64, Longitude: float64}surrealdb.GeometryPoint{Latitude: 11.11, Longitude: 22.22
Geometry Linesurrealdb.GeometryLine{GeometricPoint1, GeometricPoint2,... }
Geometry Polygonsurrealdb.GeometryPolygon{GeometryLine1, GeometryLine2,... }
Geometry Multipointsurrealdb.GeometryMultiPoint{GeometryPoint1, GeometryPoint2,... }
Geometry MultiLinesurrealdb.GeometryMultiLine{GeometryLine1, GeometryLine2,... }
Geometry MultiPolygonsurrealdb.GeometryMultiPolygon{GeometryPolygon1, GeometryPolygon2,... }
Geometry Collectionsurrealdb.GeometryMultiPolygon{GeometryPolygon1, GeometryLine2, GeometryPoint3, GeometryMultiPoint4,... }


Helper Types

surrealdb.O

For some methods like create, insert, update, you can pass a map instead of an struct value. An example:

person, err := surrealdb.Create[Person](db, models.Table("persons"), map[interface{}]interface{}{ "Name": "John", "Surname": "Doe", "Location": models.NewGeometryPoint(-0.11, 22.00), })

This can be simplified to:

person, err := surrealdb.Create[Person](db, models.Table("persons"), surrealdb.O{ "Name": "John", "Surname": "Doe", "Location": models.NewGeometryPoint(-0.11, 22.00), })

Where surrealdb.O is defined below. There is no special advantage in using this other than simplicity/legibility.

type surrealdb.O map[interface{}]interface{}

surrealdb.Result[T]

This is useful for the Send function where T is the expected response type for a request. An example:

var res surrealdb.Result[[]Users] err := db.Send(&res, "select", model.Table("users")) if err != nil { panic(err) } fmt.Printf("users: %+v\n", users.R)

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install