RecordID
The RecordID struct represents a SurrealDB record identifier. A record ID consists of a table name and an identifier value, providing a typed way to reference records without ambiguity from string parsing.
Package: github.com/surrealdb/surrealdb.go/pkg/models
Source: pkg/models/record_id.go
Definition
The ID field can be any CBOR-serializable value: a string, integer, array, or map.
Constructors
NewRecordID
Creates a new RecordID with the given table name and ID.
| Parameter | Type | Description |
|---|---|---|
tableName | string | The table name. |
id | any | The record identifier value. |
Returns: RecordID
Examples
ParseRecordID
Parses a string of the form "table:id" into a RecordID. Only works for simple IDs without colons.
| Parameter | Type | Description |
|---|---|---|
idStr | string | A string in the form "table:id". |
Returns: (*RecordID, error)
Returns ErrBadRecordID if the string does not contain exactly one colon.
Methods
.String()
Returns the string representation of the record ID in the form "table:id".
Returns: string
.SurrealString()
Returns the SurrealQL representation of the record ID in the form r'table:id'.
Returns: string
CBOR Encoding
RecordID is encoded as CBOR tag 8 containing a two-element array [table, id]. The SDK handles marshaling and unmarshaling automatically when you use RecordID in structs.
See Also
Table for the table name type
Value types for the full type mapping
Data manipulation for using record IDs in CRUD operations
SurrealQL record IDs for the underlying data model