Skip to main content

databricks-isv-go-sql-driver

PWAF-compliant Databricks SQL Driver for Go (databricks-sql-go): PAT, OAuth M2M, OAuth U2M (browser + token-env + custom OAuth app PKCE), WithUserAgentEntry. Use when building or testing integrations that run SQL queries via a Databricks SQL warehouse.

설치로 이동

소스 정보

저장소
databricks-solutions/partner-ai-dev-kit
최근 소스 활동
2026년 4월 15일 00:36
감지된 SKILL.md 언어
영어
스타
5
포크
1

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
2 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
databricks-isv-go-sql-driver
description
PWAF-compliant Databricks SQL Driver for Go (databricks-sql-go): PAT, OAuth M2M, OAuth U2M (browser + token-env + custom OAuth app PKCE), WithUserAgentEntry. Use when building or testing integrations that run SQL queries via a Databricks SQL warehouse.
<!-- skill-version: 1.0.0 --> # Databricks SQL Driver for Go (ISV) Use this skill when implementing or testing **Databricks SQL Driver for Go** (`databricks-sql-go`) integrations for PWAF-compliant SQL query execution via a Databricks SQL warehouse. ## PWAF Documentation Links | Resource | URL | |----------|-----| | **PWAF Home** | https://databrickslabs.github.io/partner-architecture/ | | **Authentication Best Practices** | https://databrickslabs.github.io/partner-architecture/isv-partners/lakehouse-patterns/access-auth/ | | **OAuth M2M Guide** | https://databrickslabs.github.io/partner-architecture/isv-partners/lakehouse-patterns/access-auth/oauth-m2m | | **OAuth U2M Guide** | https://databrickslabs.github.io/partner-architecture/isv-partners/lakehouse-patterns/access-auth/oauth-u2m | | **User-Agent (SQL Drivers)** | https://databrickslabs.github.io/partner-architecture/isv-partners/telemetry-attribution/sql-drivers | | **Databricks SQL Driver for Go** | https://docs.databricks.com/aws/en/dev-tools/go-sql-driver | | **GitHub** | https://github.com/databricks/databricks-sql-go | ## Requirements - **Driver:** `github.com/databricks/databricks-sql-go` v1.5.2+ - **Go:** 1.20+ - **SQL Warehouse:** Required (`DATABRICKS_HTTP_PATH`) - **Install:** `go get github.com/databricks/databricks-sql-go@latest` ## Authentication Comparison | Method | PWAF Status | Auto Token Refresh | Browser Required | Use Case | |--------|-------------|-------------------|------------------|----------| | PAT | ⚠️ Limited | No | No | Testing only | | OAuth M2M | ✅ Recommended | Yes (driver-native) | No | Production/automated | | U2M Custom OAuth | ✅ Recommended (ISV) | No | Yes | Interactive (custom app) | | U2M Token-Env | ✅ Supported | No | No | Headless/CI | **ISV Note:** For user-interactive flows, use **U2M Custom OAuth** with your registered OAuth app (Account Console → App connections). This provides custom branding, audit trails, and scoped permissions. The driver's built-in U2M browser auth uses a generic `databricks-sql-connector` app which is not appropriate for ISV applications. --- ## Host Normalization Helper The driver's `WithServerHostname` expects a **bare hostname** (no `https://`): ```go import "strings" func serverHostname(host string) string { s := strings.TrimPrefix(host, "https://") s = strings.TrimPrefix(s, "http://") if idx := strings.Index(s, "/"); idx >= 0 { s = s[:idx] } return s } ``` --- ## Environment Variables Reference | Variable | Required For | Description | |----------|-------------|-------------| | `DATABRICKS_HOST` | All | Workspace URL (e.g., `https://myworkspace.cloud.databricks.com`) | | `DATABRICKS_HTTP_PATH` | All | SQL warehouse HTTP path (e.g., `/sql/1.0/warehouses/abc123`) | | `DATABRICKS_TOKEN` | PAT | Personal access token | | `DATABRICKS_CLIENT_ID` | OAuth M2M | Service principal UUID | | `DATABRICKS_CLIENT_SECRET` | OAuth M2M | Service principal OAuth secret | | `DATABRICKS_U2M_CLIENT_ID` | U2M Custom OAuth | Custom OAuth app client ID from App connections | | `DATABRICKS_U2M_CLIENT_SECRET` | U2M Custom OAuth (optional) | Custom OAuth app client secret | | `DATABRICKS_REDIRECT_URI` | U2M Custom OAuth (optional) | Custom redirect URI (default: `http://localhost:8040/callback`) | | `DATABRICKS_ACCESS_TOKEN` | U2M Token-Env | Pre-obtained OAuth access token | | `DATABRICKS_AUTH_TYPE` | Multi-auth | Auth type selector: `pat`, `oauth_m2m`, `u2m_browser`, `u2m_custom_oauth`, `u2m_token_env` | **Important:** Do not mix M2M and U2M environment variables. Use `env -i` for clean test environments. --- ## Complete Examples ### PAT Authentication (Testing Only) ```go package main import ( "database/sql" "fmt" "os" "strings" dbsql "github.com/databricks/databricks-sql-go" ) func main() { host := os.Getenv("DATABRICKS_HOST") httpPath := os.Getenv("DATABRICKS_HTTP_PATH") token := os.Getenv("DATABRICKS_TOKEN") connector, err := dbsql.NewConnector( dbsql.WithServerHostname(serverHostname(host)), dbsql.WithPort(443), dbsql.WithHTTPPath(httpPath), dbsql.WithAccessToken(token), dbsql.WithUserAgentEntry("YourCompany_YourProduct/1.0.0"), ) if err != nil { panic(err) } db := sql.OpenDB(connector) defer db.Close() rows, err := db.Query("SELECT COUNT(*) FROM samples.nyctaxi.trips") if err != nil { panic(err) } defer rows.Close() var count int64 rows.Next() rows.Scan(&count) fmt.Printf("PAT OK: %d trips\n", count) } func serverHostname(host string) string { s := strings.TrimPrefix(host, "https://") s = strings.TrimPrefix(s, "http://") if idx := strings.Index(s, "/"); idx >= 0 { s = s[:idx] } return s } ``` **Env vars:** `DATABRICKS_HOST`, `DATABRICKS_HTTP_PATH`, `DATABRICKS_TOKEN` --- ### OAuth M2M Authentication (Production Recommended) Uses the driver's **built-in M2M authenticator** that handles token fetch and refresh: ```go package main import ( "database/sql" "fmt" "os" "strings" dbsql "github.com/databricks/databricks-sql-go" "github.com/databricks/databricks-sql-go/auth/oauth/m2m" ) func main() { host := os.Getenv("DATABRICKS_HOST") httpPath := os.Getenv("DATABRICKS_HTTP_PATH") clientID := os.Getenv("DATABRICKS_CLIENT_ID") clientSecret := os.Getenv("DATABRICKS_CLIENT_SECRET") authenticator := m2m.NewAuthenticator(clientID, clientSecret, serverHostname(host)) connector, err := dbsql.NewConnector( dbsql.WithServerHostname(serverHostname(host)), dbsql.WithPort(443), dbsql.WithHTTPPath(httpPath), dbsql.WithAuthenticator(authenticator), dbsql.WithUserAgentEntry("YourCompany_YourProduct/1.0.0"), ) if err != nil { panic(err) } db := sql.OpenDB(connector) defer db.Close() rows, err := db.Query("SELECT COUNT(*) FROM samples.nyctaxi.trips") if err != nil { panic(err) } defer rows.Close() var count int64 rows.Next() rows.Scan(&count) fmt.Printf("OAuth M2M OK: %d trips\n", count) } func serverHostname(host string) string { s := strings.TrimPrefix(host, "https://") s = strings.TrimPrefix(s, "http://") if idx := strings.Index(s, "/"); idx >= 0 { s = s[:idx] } return s } ``` **Env vars:** `DATABRICKS_HOST`, `DATABRICKS_HTTP_PATH`, `DATABRICKS_CLIENT_ID`, `DATABRICKS_CLIENT_SECRET` **Setup:** Create service principal in Account Console → Settings → Service principals. Generate OAuth secret. Grant `CAN_USE` on the SQL warehouse. --- ### U2M Browser Authentication (Driver-Native) Uses the driver's **built-in U2M authenticator** that opens the user's default browser: ```go package main import ( "database/sql" "fmt" "os" "strings" "time" dbsql "github.com/databricks/databricks-sql-go" "github.com/databricks/databricks-sql-go/auth/oauth/u2m" ) func main() { host := os.Getenv("DATABRICKS_HOST") httpPath := os.Getenv("DATABRICKS_HTTP_PATH") authenticator, err := u2m.NewAuthenticator(serverHostname(host), 2*time.Minute) if err != nil { panic(err) } connector, err := dbsql.NewConnector( dbsql.WithServerHostname(serverHostname(host)), dbsql.WithPort(443), dbsql.WithHTTPPath(httpPath), dbsql.WithAuthenticator(authenticator), dbsql.WithUserAgentEntry("YourCompany_YourProduct/1.0.0"), ) if err != nil { panic(err) } db := sql.OpenDB(connector) defer db.Close() rows, err := db.Query("SELECT COUNT(*) FROM samples.nyctaxi.trips") if err != nil { panic(err) } defer rows.Close() var count int64 rows.Next() rows.Scan(&count) fmt.Printf("U2M Browser OK: %d trips\n", count) } func serverHostname(host string) string { s := strings.TrimPrefix(host, "https://") s = strings.TrimPrefix(s, "http://") if idx := strings.Index(s, "/"); idx >= 0 { s = s[:idx] } return s } ``` **Env vars:** `DATABRICKS_HOST`, `DATABRICKS_HTTP_PATH` **Notes:** - Uses Databricks' built-in OAuth app (client_id=`databricks-sql-connector`) - Do NOT set `DATABRICKS_CLIENT_ID` or `DATABRICKS_TOKEN` - Driver picks an available localhost port at runtime --- ### U2M Token-Env Authentication (Headless/CI) Pass a pre-obtained OAuth access token: ```go package main import ( "database/sql" "fmt" "os" "strings" dbsql "github.com/databricks/databricks-sql-go" ) func main() { host := os.Getenv("DATABRICKS_HOST") httpPath := os.Getenv("DATABRICKS_HTTP_PATH") token := os.Getenv("DATABRICKS_ACCESS_TOKEN") if token == "" { token = os.Getenv("DATABRICKS_TOKEN") } connector, err := dbsql.NewConnector( dbsql.WithServerHostname(serverHostname(host)), dbsql.WithPort(443), dbsql.WithHTTPPath(httpPath), dbsql.WithAccessToken(token), dbsql.WithUserAgentEntry("YourCompany_YourProduct/1.0.0"), ) if err != nil { panic(err) } db := sql.OpenDB(connector) defer db.Close() rows, err := db.Query("SELECT COUNT(*) FROM samples.nyctaxi.trips") if err != nil { panic(err) } defer rows.Close() var count int64 rows.Next() rows.Scan(&count) fmt.Printf("U2M Token-Env OK: %d trips\n", count) } func serverHostname(host string) string { s := strings.TrimPrefix(host, "https://") s = strings.TrimPrefix(s, "http://") if idx := strings.Index(s, "/"); idx >= 0 { s = s[:idx] } return s } ``` **Env vars:** `DATABRICKS_HOST`, `DATABRICKS_HTTP_PATH`, `DATABRICKS_ACCESS_TOKEN` (or `DATABRICKS_TOKEN`) --- ### U2M Custom OAuth App (PKCE) - Interactive For user-interactive flows with a custom OAuth app: ```go package main import ( "context" "crypto/rand" "crypto/sha256" "database/sql" "encoding/base64" "encoding/json" "fmt"
GitHub에서 보기
이 SKILL.md는 매우 커서 SkillsMP가 여기에는 첫 섹션만 미리 보여줍니다. GitHub에서 보기