supabase

package module
v0.1.0-alpha.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package supabase is the convenience entry point to the Supabase Go SDK. It composes the SDK's domain modules behind a single configured client. The Database client is reached through Client.Database and the Auth client through Client.Auth.

There are two ways to use the SDK. Importing this package wires the shared transport, API key, and options through one place. Callers who need only one domain may instead import that module directly (for example github.com/supabase/supabase-go/postgrest) and pull in only it and the core module's github.com/supabase/supabase-go/core/configuration package.

The SDK repository's example programs include an HTTP backend that verifies each request's token, then queries the database as that user.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the composed Supabase client. It is safe for concurrent use by multiple goroutines. Construct it with New. The zero value is not usable.

func New

func New(projectURL, apiKey string, options ...configuration.Option) (*Client, error)

New constructs a Supabase client for the given project URL and API key.

The apiKey may be any Supabase project API key. Pass the publishable key for access governed by Row Level Security, attaching per-request user tokens so queries run as the end user, or the secret key for privileged access that bypasses Row Level Security. See https://supabase.com/docs/guides/getting-started/api-keys for the key types.

Returned sentinel errors relate to misconfiguration:

See configuration.WithHTTPClient, configuration.WithHeader, configuration.WithRetry and configuration.WithLogger for the available options.

Example

ExampleNew customizes the client with the shared functional options from the configuration package: a caller-supplied HTTP client and global headers sent on every request.

package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/supabase/supabase-go"
	"github.com/supabase/supabase-go/core/configuration"
)

func main() {
	client, err := supabase.New(
		"https://PROJECT_ID.supabase.co",
		"sb_publishable_...",
		configuration.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
		configuration.WithHeader("X-App-Version", "1.0.0+user.generated"),
	)
	fmt.Println(client != nil && err == nil)
}
Output:
true

func (*Client) Auth

func (c *Client) Auth() *auth.Client

Auth returns the composed Auth client, which verifies end-user access tokens and fetches the profiles they authenticate:

result, err := supabase.Auth().GetClaims(ctx, token)
Example

ExampleClient_Auth verifies an inbound end-user access token and then queries the Database as that user, the composed backend flow: Row Level Security confines the result to the verified user's own rows. It requires a reachable Supabase project, so it is compiled but not run by go test.

package main

import (
	"context"
	"fmt"

	"github.com/supabase/supabase-go"
	"github.com/supabase/supabase-go/postgrest"
)

func main() {
	type PracticeLog struct {
		UserID string `json:"user_id"`
		Piece  string `json:"piece"`
	}

	client, err := supabase.New("https://PROJECT_ID.supabase.co", "sb_publishable_...")
	if err != nil {
		fmt.Println(err)
		return
	}

	// The token arrives on an inbound request, for example from its
	// Authorization: Bearer header.
	token := "END_USER_ACCESS_TOKEN"

	verified, err := client.Auth().GetClaims(context.Background(), token)
	if err != nil {
		fmt.Println(err)
		return
	}

	userDatabase := client.Database().WithAccessTokenProvider(
		func(context.Context) (string, error) { return token, nil },
	)
	logs, _, err := postgrest.Collect(
		context.Background(),
		userDatabase,
		postgrest.From[PracticeLog]("practice_logs"),
	)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(verified.Claims().Subject(), len(logs))
}

func (*Client) Database

func (c *Client) Database() *postgrest.Client

Database returns the composed Database client, through which queries built with postgrest.From execute:

rows, response, err := postgrest.Collect(
    ctx,
    supabase.Database(),
    postgrest.From[Instrument]("instruments").Select("id, name"))
Example

ExampleClient_Database runs a basic Database query for zero or more rows. It requires a reachable Supabase project, so it is compiled but not run by go test.

package main

import (
	"context"
	"errors"
	"fmt"

	"github.com/supabase/supabase-go"
	"github.com/supabase/supabase-go/postgrest"
)

func main() {
	type Instrument struct {
		ID   int    `json:"id"`
		Name string `json:"name"`
	}

	client, err := supabase.New("https://PROJECT_ID.supabase.co", "sb_publishable_...")
	if err != nil {
		fmt.Println(err)
		return
	}

	instruments, response, err := postgrest.Collect(
		context.Background(),
		client.Database(),
		postgrest.
			From[Instrument]("instruments").
			Select("id, name"),
	)
	if err != nil {
		if postgrestError, ok := errors.AsType[*postgrest.Error](err); ok {
			// Branch on the stable code, not the message text. When the
			// database knows the fix it says so in Hint.
			fmt.Println(postgrestError.Code, postgrestError.Hint)
			return
		}
		fmt.Println(err)
		return
	}
	fmt.Println(len(instruments), response.HTTPStatus)
}

Directories

Path Synopsis
auth module
core module
integration-testing
testkit module
postgrest module
supabase module
tools
go module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL