Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ client, err := supabase.NewClient(url, key, options)

For more see [postgrest-go Query Builder documentation](https://pkg.go.dev/github.com/supabase-community/postgrest-go#QueryBuilder)

### Accessing the PostgREST Client

```go
restClient := client.Rest()
restClient.ChangeSchema("custom_schema")

// Access PostgREST client errors
if err := client.RestError(); err != nil {
log.Printf("PostgREST error: %v", err)
}
```

### Authentication

The client provides comprehensive authentication features through the integrated GoTrue client.
Expand Down
14 changes: 14 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ func NewClient(url, key string, options *ClientOptions) (*Client, error) {
return client, nil
}

// Returns the underlying PostgREST client used by this Supabase Client
func (c *Client) Rest() *postgrest.Client {
return c.rest
}

// Returns last recorded error by the underlying PostgREST client
// Returns nil if the REST client is uninitialized or no error has occurred
func (c *Client) RestError() error {
if c.rest == nil {
return nil
}
return c.rest.ClientError
}

// Wrap postgrest From method
// From returns a QueryBuilder for the specified table.
func (c *Client) From(table string) *postgrest.QueryBuilder {
Expand Down
28 changes: 28 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,31 @@ func TestFunctions(t *testing.T) {
}
t.Logf("function invokation result: %v", result)
}

func TestRest(t *testing.T) {
client, err := supabase.NewClient(API_URL, API_KEY, nil)
if err != nil {
t.Errorf("cannot initialize client: %v", err)
}

restClient := client.Rest()
if restClient == nil {
t.Error("Rest() returned nil, expected non-nil postgrest.Client")
}
t.Logf("Rest() returned: %v", restClient)
}

func TestRestError(t *testing.T) {
client, err := supabase.NewClient(API_URL, API_KEY, nil)
if err != nil {
t.Errorf("cannot initialize client: %v", err)
}

// Test that RestError returns nil when no error has occurred
restErr := client.RestError()
if restErr != nil {
t.Errorf("RestError() returned error when none expected: %v", restErr)
}

t.Logf("RestError() returned: %v", restErr)
}