### Initialize Basic Supabase Client Source: https://github.com/supabase-community/supabase-go/blob/main/README.md A minimal example for initializing the Supabase client with only the URL and key. ```go client, err := supabase.NewClient(url, key, nil) ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Install pre-commit and then install the repository's pre-commit hooks to ensure code quality before committing. ```bash pip install pre-commit ``` ```bash pre-commit install ``` -------------------------------- ### Install Supabase Go Client Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Use this command to add the Supabase Go client library to your project. ```sh go get github.com/supabase-community/supabase-go ``` -------------------------------- ### Run All Tests Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Execute all tests in the project to verify your setup and changes. ```bash go test ./... ``` -------------------------------- ### Initialize Supabase Client and Manage Storage Source: https://context7.com/supabase-community/supabase-go/llms.txt Initializes the Supabase client and demonstrates operations for getting bucket information and listing all buckets. Ensure you replace placeholder URLs and keys with your actual Supabase project details. ```go package main import ( "fmt" "log" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-api-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Get bucket information bucket, err := client.Storage.GetBucket("avatars") if err != nil { log.Fatal("Failed to get bucket:", err) } fmt.Printf("Bucket: %s, Public: %v\n", bucket.Name, bucket.Public) // List all buckets buckets, err := client.Storage.ListBuckets() if err != nil { log.Fatal("Failed to list buckets:", err) } for _, b := range buckets { fmt.Printf("Bucket: %s\n", b.Name) } } ``` -------------------------------- ### Example Commit Message Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md An example of a clear and descriptive commit message following best practices, including a summary, details, and issue reference. ```text Add support for custom timeout configuration - Add Timeout field to ClientOptions - Update client initialization to respect timeout - Add tests for timeout behavior Fixes #456 ``` -------------------------------- ### Invoke Supabase Edge Functions Source: https://context7.com/supabase-community/supabase-go/llms.txt Demonstrates how to invoke Supabase Edge Functions, including passing parameters and handling responses. This example shows invoking a simple 'hello_world' function and a more complex 'process_order' function. ```go package main import ( "fmt" "log" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-api-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Invoke an edge function with parameters result, err := client.Functions.Invoke("hello_world", map[string]interface{}{ "name": "World", }) if err != nil { log.Fatal("Function invocation failed:", err) } fmt.Printf("Function result: %v\n", result) // Invoke a more complex function orderResult, err := client.Functions.Invoke("process_order", map[string]interface{}{ "order_id": "ord_12345", "customer_id": "cust_67890", "items": []map[string]interface{}{ {"product_id": "prod_001", "quantity": 2}, {"product_id": "prod_002", "quantity": 1}, }, }) if err != nil { log.Fatal("Order processing failed:", err) } fmt.Printf("Order result: %v\n", orderResult) } ``` -------------------------------- ### Query Data from Supabase Table Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Select all columns from the 'countries' table. This example uses the Postgrest Query Builder. ```go data, count, err := client.From("countries").Select("*", "exact", false).Execute() ``` -------------------------------- ### Download Go Dependencies Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Download all necessary Go dependencies for the project. ```bash go mod download ``` -------------------------------- ### Initialize Supabase Client Source: https://context7.com/supabase-community/supabase-go/llms.txt Creates a new Supabase client instance. Supports basic initialization or with custom options like headers and schema. ```go package main import ( "fmt" "log" "github.com/supabase-community/supabase-go" ) func main() { // Basic client initialization client, err := supabase.NewClient( "https://your-project.supabase.co", "your-api-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } fmt.Println("Client initialized successfully") // Client with custom options options := &supabase.ClientOptions{ Headers: map[string]string{ "X-Custom-Header": "custom-value", }, Schema: "custom_schema", // defaults to "public" } clientWithOptions, err := supabase.NewClient( "https://your-project.supabase.co", "your-api-key", options, ) if err != nil { log.Fatal("Failed to initialize client:", err) } fmt.Println("Client with custom options initialized") } ``` -------------------------------- ### Initialize Supabase Client Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Initialize the Supabase client with your API URL and public key. Ensure error handling for initialization failures. ```go client, err := supabase.NewClient(API_URL, API_KEY, &supabase.ClientOptions{}) if err != nil { fmt.Println("Failed to initalize the client: ", err) } ``` -------------------------------- ### Initialize Supabase Client with Custom Options Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Configure the Supabase client with custom headers and a specific schema. The default schema is 'public'. ```go options := &supabase.ClientOptions{ Headers: map[string]string{ "X-Custom-Header": "custom-value", }, Schema: "custom_schema", // defaults to "public" } client, err := supabase.NewClient(url, key, options) ``` -------------------------------- ### Sign In with Email and Password Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Authenticate a user using their email and password. Handles potential sign-in errors and prints user details upon success. ```go // Sign in with email and password session, err := client.SignInWithEmailPassword("user@example.com", "password") if err != nil { log.Fatal("Sign in failed:", err) } fmt.Printf("User ID: %s\n", session.User.ID) fmt.Printf("Access Token: %s\n", session.AccessToken) ``` -------------------------------- ### Sign In with Phone and Password Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Authenticate a user using their phone number and password. Ensure the phone number is in the correct international format. ```go // Sign in with phone and password session, err := client.SignInWithPhonePassword("+1234567890", "password") if err != nil { log.Fatal("Sign in failed:", err) } ``` -------------------------------- ### Clone the Supabase Go Repository Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Clone the Supabase Go repository to your local machine. Replace YOUR_USERNAME with your GitHub username. ```bash git clone https://github.com/YOUR_USERNAME/supabase-go.git cd supabase-go ``` -------------------------------- ### Sign In with Email and Password Source: https://context7.com/supabase-community/supabase-go/llms.txt Authenticates a user using their email and password. This method returns a session object containing user details and authentication tokens. Subsequent requests to protected resources will use the authenticated session. ```go package main import ( "fmt" "log" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-anon-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Sign in with email and password session, err := client.SignInWithEmailPassword("user@example.com", "secure-password") if err != nil { log.Fatal("Sign in failed:", err) } fmt.Printf("User ID: %s\n", session.User.ID) fmt.Printf("Email: %s\n", session.User.Email) fmt.Printf("Access Token: %s...\n", session.AccessToken[:20]) fmt.Printf("Token expires in: %d seconds\n", session.ExpiresIn) // Now all subsequent requests use the authenticated session data, _, err := client.From("protected_table").Select("*", "", false).Execute() if err != nil { log.Fatal("Query failed:", err) } fmt.Printf("Protected data: %s\n", string(data)) } ``` -------------------------------- ### Sign In with Phone and Password Source: https://context7.com/supabase-community/supabase-go/llms.txt Authenticates a user using their phone number and password. Similar to email authentication, this returns a session object and updates the client's authentication state for subsequent requests. ```go package main import ( "fmt" "log" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-anon-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Sign in with phone and password session, err := client.SignInWithPhonePassword("+1234567890", "secure-password") if err != nil { log.Fatal("Sign in failed:", err) } fmt.Printf("User ID: %s\n", session.User.ID) fmt.Printf("Phone: %s\n", session.User.Phone) fmt.Printf("Access Token: %s...\n", session.AccessToken[:20]) } ``` -------------------------------- ### Query Database Tables with Supabase Go Source: https://context7.com/supabase-community/supabase-go/llms.txt Returns a QueryBuilder for database table operations (SELECT, INSERT, UPDATE, DELETE). Supports filtering, ordering, and pagination via PostgREST. ```go package main import ( "encoding/json" "fmt" "log" "github.com/supabase-community/supabase-go" ) type Country struct { ID int `json:"id"` Name string `json:"name"` Code string `json:"code"` } func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-api-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Select all rows with exact count data, count, err := client.From("countries").Select("*", "exact", false).Execute() if err != nil { log.Fatal("Query failed:", err) } fmt.Printf("Found %d countries\n", count) // Parse response into struct var countries []Country if err := json.Unmarshal(data, &countries); err != nil { log.Fatal("Failed to parse response:", err) } for _, country := range countries { fmt.Printf("Country: %s (%s)\n", country.Name, country.Code) } // Select with filters data, _, err = client.From("countries"). Select("name, code", "", false). Eq("code", "US"). Execute() if err != nil { log.Fatal("Filtered query failed:", err) } fmt.Printf("US data: %s\n", string(data)) } ``` -------------------------------- ### Run Pre-commit Checks Manually Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Optionally, run all pre-commit checks manually across all files before committing. ```bash pre-commit run --all-files ``` -------------------------------- ### Manually Update Authentication Session Source: https://context7.com/supabase-community/supabase-go/llms.txt Shows how to manually update the authentication session for all service clients using a provided session object. This is useful when you have an external session that needs to be applied to the client. ```go package main import ( "fmt" "log" "github.com/supabase-community/auth-go/types" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-anon-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // If you have a session from another source (e.g., stored session) storedSession := types.Session{ AccessToken: "your-stored-access-token", RefreshToken: "your-stored-refresh-token", ExpiresIn: 3600, } // Update all service clients with this session client.UpdateAuthSession(storedSession) fmt.Println("Session updated across all clients") // Now all requests use the updated session data, _, err := client.From("protected_table").Select("*", "", false).Execute() if err != nil { log.Fatal("Query failed:", err) } fmt.Printf("Data: %s\n", string(data)) } ``` -------------------------------- ### Push Branch to Fork Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Push your local branch containing your changes to your fork on GitHub. ```bash git push origin your-branch-name ``` -------------------------------- ### Enable Automatic Token Refresh Source: https://context7.com/supabase-community/supabase-go/llms.txt Enables background automatic token refresh for long-running applications. The client automatically refreshes tokens at 75% of their expiry time and implements exponential backoff for retry logic on failures, ensuring a continuous valid session. ```go package main import ( "fmt" "log" "time" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-anon-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Sign in session, err := client.SignInWithEmailPassword("user@example.com", "password") if err != nil { log.Fatal("Sign in failed:", err) } // Enable automatic token refresh in background // - Refreshes at 75% of token expiry time // - Retries with exponential backoff (1s, 2s, 4s) on failure // - Falls back to 30s retry interval after 3 failures client.EnableTokenAutoRefresh(session) fmt.Println("Auto-refresh enabled. Client will maintain valid session.") // Your long-running application logic for { // All requests automatically use refreshed tokens data, _, err := client.From("events").Select("*", "", false).Execute() if err != nil { log.Printf("Query error: %v", err) } else { fmt.Printf("Events: %s\n", string(data)) } time.Sleep(1 * time.Minute) } } ``` -------------------------------- ### Bypass Pre-commit Hooks Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Use this command to bypass pre-commit hooks during a commit, though it is not recommended. ```bash git commit --no-verify -m "Your commit message" ``` -------------------------------- ### Create a New Feature Branch Source: https://github.com/supabase-community/supabase-go/blob/main/CONTRIBUTING.md Create a new Git branch for your feature or bug fix, branching from the 'main' branch. ```bash git checkout -b feature/your-feature-name ``` ```bash git checkout -b fix/your-bug-fix ``` -------------------------------- ### Call Database Functions with Supabase Go Source: https://context7.com/supabase-community/supabase-go/llms.txt Invokes PostgreSQL functions (stored procedures) in your Supabase database. Supports functions with or without parameters. ```go package main import ( "fmt" "log" "github.com/supabase-community/supabase-go" ) func main() { client, err := supabase.NewClient( "https://your-project.supabase.co", "your-api-key", nil, ) if err != nil { log.Fatal("Failed to initialize client:", err) } // Call a simple function with no parameters result := client.Rpc("hello_world", "", nil) fmt.Printf("Function result: %s\n", result) // Call a function with parameters params := map[string]interface{}{ "user_id": 123, "new_score": 500, } result = client.Rpc("update_user_score", "exact", params) fmt.Printf("Update result: %s\n", result) } ``` -------------------------------- ### Enable Automatic Token Refresh Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Automatically refresh authentication tokens in the background before they expire. The client handles retries and updates service clients with new tokens. ```go // Enable automatic token refresh in the background client.EnableTokenAutoRefresh(session) // The client will automatically: // - Refresh tokens before they expire (at 75% of expiry time) // - Retry failed refreshes with exponential backoff // - Update all service clients with new tokens ``` -------------------------------- ### Manually Refresh Authentication Token Source: https://github.com/supabase-community/supabase-go/blob/main/README.md Manually refresh an expired user session token using the provided refresh token. This is useful when automatic refresh is not enabled or fails. ```go // Refresh an expired token newSession, err := client.RefreshToken(session.RefreshToken) if err != nil { log.Fatal("Token refresh failed:", err) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.