githubEdit

Quick Start

This guide walks you through creating your first SOM-powered application.

Note: This package is currently tested against SurrealDB version 3.0.0arrow-up-right.

Disclaimer

This library is currently considered HIGHLY EXPERIMENTAL and under heavy development. While basic functionality works, there could be unknown bugs. Not recommended for production use without thorough testing.

Step 1: Define Your Model

First, generate the static base files so types like som.Node are available:

go run github.com/go-surreal/som@latest

Create model/user.go:

package model

import "yourproject/gen/som"

type User struct {
    som.Node[som.ULID]
    som.Timestamps

    Username string
    Email    string
    Age      int
    IsActive bool
}

Key points:

  • som.Node[som.ULID] makes this a database record with ULID-based IDs (required)

  • som.Timestamps adds auto-managed timestamp fields (optional)

  • Field names become database field names (snake_case by default)

  • You can override field names with the som:"custom_name" tag

Step 2: Generate Code

This creates:

  • gen/som/ - Client and repository code

  • gen/som/filter/ - Type-safe filters

  • gen/som/by/ - Sorting helpers

Step 3: Connect and Use

Step 4: Query Patterns

Find First Match

Check Existence

Count Records

Async Operations

Next Steps

Last updated