Skip to content

Commit 2ab6f0f

Browse files
authored
Document go driver (#67)
1 parent bea93be commit 2ab6f0f

File tree

1 file changed

+65
-0
lines changed
  • content/en/user-guide/snowflake-drivers

1 file changed

+65
-0
lines changed

content/en/user-guide/snowflake-drivers/index.md

+65
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,68 @@ connection.execute({
8888
}
8989
});
9090
```
91+
92+
## Go Driver
93+
94+
The Go Snowflake driver provides a way to connect to Snowflake and perform database operations using Go. You can use this driver to connect to the Snowflake emulator for testing your Snowflake integrations in Go.
95+
96+
To install the Go Snowflake driver, execute the following command:
97+
98+
{{< command >}}
99+
$ go get github.com/snowflakedb/gosnowflake
100+
{{< /command >}}
101+
102+
The connection string follows the format `username:password@host:port/database?account=account_name`. For the emulator use:
103+
`test:[email protected]:4566/test?account=test`
104+
105+
Here's an example of how to connect to the Snowflake emulator using Go:
106+
107+
```go
108+
package main
109+
110+
import (
111+
"database/sql"
112+
"fmt"
113+
"log"
114+
115+
_ "github.com/snowflakedb/gosnowflake"
116+
)
117+
118+
func main() {
119+
// Connection string
120+
connectionString := "test:[email protected]:4566/test?account=test"
121+
122+
// Connect to LocalStack Snowflake
123+
db, err := sql.Open("snowflake", connectionString)
124+
if err != nil {
125+
log.Fatalf("Failed to connect to Snowflake: %v", err)
126+
}
127+
defer db.Close()
128+
129+
// Ping the database to verify the connection
130+
if err := db.Ping(); err != nil {
131+
log.Fatalf("Failed to ping Snowflake: %v", err)
132+
}
133+
fmt.Println("Successfully connected to Snowflake!")
134+
135+
// Execute a simple query
136+
rows, err := db.Query("SELECT 123")
137+
if err != nil {
138+
log.Fatalf("Failed to execute query: %v", err)
139+
}
140+
defer rows.Close()
141+
142+
// Process the result
143+
var version string
144+
for rows.Next() {
145+
if err := rows.Scan(&version); err != nil {
146+
log.Fatalf("Failed to scan row: %v", err)
147+
}
148+
fmt.Printf("Query result: %s\n", version)
149+
}
150+
151+
if err := rows.Err(); err != nil {
152+
log.Fatalf("Error iterating rows: %v", err)
153+
}
154+
}
155+
```

0 commit comments

Comments
 (0)