# RecordID

The RecordID type represents a SurrealDB record identifier consisting of a table name and an ID value.

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](https://github.com/surrealdb/surrealdb.go/blob/main/pkg/models/record_id.go)

---

## Definition

```go
type RecordID struct {
    Table string
    ID    any
}
```

The `ID` field can be any CBOR-serializable value: a string, integer, array, or map.

---

## Constructors

### `NewRecordID` {#newrecordid}

Creates a new `RecordID` with the given table name and ID.

```go title="Syntax"
id := models.NewRecordID(tableName, id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>tableName</code> _(required)_</td>
            <td><code>string</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>any</code></td>
            <td>The record identifier value.</td>
        </tr>
    </tbody>
</table>

**Returns:** `RecordID`

#### Examples

```go
id := models.NewRecordID("persons", "tobie")

numericID := models.NewRecordID("events", 42)

compositeID := models.NewRecordID("access", []any{"us", 2026})
```

### `ParseRecordID` {#parserecordid}

Parses a string of the form `"table:id"` into a `RecordID`. Only works for simple IDs without colons.

```go title="Syntax"
id, err := models.ParseRecordID(idStr)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>idStr</code> _(required)_</td>
            <td><code>string</code></td>
            <td>A string in the form <code>"table:id"</code>.</td>
        </tr>
    </tbody>
</table>

**Returns:** `(*RecordID, error)`

Returns `ErrBadRecordID` if the string does not contain exactly one colon.

---

## Methods

### `.String()` {#string}

Returns the string representation of the record ID in the form `"table:id"`.

```go title="Syntax"
s := id.String()
```

**Returns:** `string`

### `.SurrealString()` {#surrealstring}

Returns the SurrealQL representation of the record ID in the form `r'table:id'`.

```go title="Syntax"
s := id.SurrealString()
```

**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.

```go
type Person struct {
    ID      *models.RecordID `json:"id,omitempty"`
    Name    string           `json:"name"`
}
```

---

## See also

- [Table](/docs/reference/golang/api/values/table.md) for the table name type
- [Value types](/docs/reference/golang/concepts/value-types.md) for the full type mapping
- [Data manipulation](/docs/reference/golang/concepts/data-manipulation.md) for using record IDs in CRUD operations
- [SurrealQL record IDs](/docs/reference/query-language/language-primitives/data-types/record-ids.md) for the underlying data model
