diff --git a/README.md b/README.md index 6f5460a..c75d4c9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/client.go b/client.go index 5baffa1..226142c 100644 --- a/client.go +++ b/client.go @@ -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 { diff --git a/client_test.go b/client_test.go index a3bd4f7..1fdd774 100644 --- a/client_test.go +++ b/client_test.go @@ -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) +}