Go SDK
The Go SDK is a zero-dependency client, that works with onyx-cli generated client stubs.
The Go SDK is a zero-dependency client, that works with onyx-cli generated client stubs.
Looking for other supported sdks?
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.
1) Install the SDK module:
go get github.com/OnyxDevTools/onyx-database-go/onyx@latest2) 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 versionLogin 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", ...}
]
}
]
}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 for your database:
onyx schema get
onyx gen --goUse 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)
}
}If you have any questions or need assistance: