PreviewRustaBase OSS is in public preview. Build on managed PostgreSQL with APIs, authentication, storage, realtime, and server-side functions.Read the product direction

APIs and SDKs

Go SDK

The official Go client is built for services, workers, and command-line tools. Every call takes a context, and one client can be shared across goroutines.

Install

go get github.com/rustabase/rustabase-go-sdk@latest

Create a client and authenticate

package main

import (
    "context"
    "log"

    rustabase "github.com/rustabase/rustabase-go-sdk"
)

func main() {
    ctx := context.Background()
    client := rustabase.New("https://my-app.rustabase.net")

    if _, err := client.Collection("users").AuthWithPassword(ctx, "[email protected]", "a-strong-password"); err != nil {
        log.Fatal(err)
    }
}

List and write records

posts, err := client.Collection("posts").GetList(ctx, 1, 20, &rustabase.ListOptions{
    Filter: "published = true",
    Sort:   "-created",
    Expand: "author",
})
if err != nil {
    return err
}
for _, post := range posts.Items {
    log.Println(post.ID, post.GetString("title"), post.GetBool("published"))
}

// decode straight into your own struct
var p struct {
    Title     string `json:"title"`
    Published bool   `json:"published"`
}
_ = posts.Items[0].Decode(&p)

Realtime

err := client.Realtime.Subscribe(ctx, []string{"orders"}, func(topic string, e *rustabase.RealtimeEvent) {
    log.Println(topic, e.Action)
})
// cancel ctx or call client.Realtime.Unsubscribe(ctx) to stop

Server tools

With a superuser session or API key, the client also manages API keys, webhooks, edge functions, and row-level security.

key, _ := client.APIKeys.Create(ctx, &rustabase.APIKeyPayload{Name: "reports", Scope: "read", Active: true})
run, _ := client.Functions.Run(ctx, "nightly-report", nil)
tables, _ := client.Rls.GetTables(ctx)

Errors and timeouts

if respErr, ok := rustabase.AsResponseError(err); ok {
    log.Printf("status=%d message=%s", respErr.Status, respErr.Message)
}

The client uses a 30 second HTTP timeout by default. Replace HTTPClient for long uploads or restores.

File uploads and downloads

Found something wrong on this page?

Fix it yourself. The link below opens this file in GitHub's editor and forks the repository for you if you need one, and your change becomes a pull request without leaving the browser.