Go SDK

The Go SDK is a zero-dependency client, that works with onyx-cli generated client stubs.

Looking for other supported sdks?

Overview

Start by creating your database and API keys in the Onyx Cloud Console. Download the config file and use onyx-cli to get your schema and generate a client.

Install

1) Install the SDK module:

go get github.com/OnyxDevTools/onyx-database-go/onyx@latest

2) Install the Onyx CLI:

# Homebrew (macOS)
brew tap OnyxDevTools/onyx-cli
brew install onyx-cli

# Or install directly
curl -fsSL https://raw.githubusercontent.com/OnyxDevTools/onyx-cli/main/scripts/install.sh | bash

onyx version

Create a database and publish a schema

Login to cloud.onyx.dev to create a database and an API key & secret.

Here is a minimal example schema:

{
  "tables": [
    {
      "name": "User",
      "identifier": {"name": "id", "generator": "UUID", "type": "String"},
      "type": "DEFAULT",
      "attributes": [
        {"name": "id","type": "String","maxSize": null,"isNullable": false},
        {"name": "status","type": "String","maxSize": null,"isNullable": false},
        {"name": "email", ...},
        {"name": "createdAt", ...}
      ]
    }
  ]
}

Configure credentials

Create an API key in Onyx Database, then either set environment variables or place an onyx-database.json in your project root.

Option A: Environment variables

export ONYX_DATABASE_API_KEY="key_abc"
export ONYX_DATABASE_API_SECRET="secret_xyz"

Option B: Project config file (onyx-database.json)

{
  "databaseId": "db_123",
  "baseUrl": "https://api.onyx.dev",
  "apiKey": "key_abc",
  "apiSecret": "secret_xyz"
}

Generate a Go client

Generate a Go client for your database:

onyx schema get
onyx gen --go

Save and query data

Use the generated client for typed operations:

package main

import (
    "context"
    "log"

    onyx "your/module/gen/onyx"
)

func main() {
    ctx := context.Background()
    db, err := onyx.New(ctx, onyx.Config{})
    if err != nil {
        log.Fatal(err)
    }

    _, err = db.Users().Save(ctx, onyx.User{
        Id:       "user_1",
        Email:    "user@example.com",
        Username: "User One",
    })
    if err != nil {
        log.Fatal(err)
    }
}

What else can I do?

Resources

Next Steps

Need Help?

If you have any questions or need assistance: