-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1634712 Support for toml file connection configuration (#1204)
- Loading branch information
1 parent
8224d28
commit 5eda091
Showing
12 changed files
with
774 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tomlfileconnection.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
include ../../gosnowflake.mak | ||
CMD_TARGET=tomlfileconnection | ||
|
||
## Install | ||
install: cinstall | ||
|
||
## Run | ||
run: crun | ||
|
||
## Lint | ||
lint: clint | ||
|
||
## Format source codes | ||
fmt: cfmt | ||
|
||
.PHONY: install run lint fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Example: How to connect to the server with the toml file configuration | ||
// Prerequiste: following the Snowflake doc: https://docs.snowflake.com/en/developer-guide/snowflake-cli-v2/connecting/specify-credentials | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"flag" | ||
"fmt" | ||
"log" | ||
|
||
_ "github.com/snowflakedb/gosnowflake" | ||
) | ||
|
||
func main() { | ||
if !flag.Parsed() { | ||
flag.Parse() | ||
} | ||
|
||
// os.Setenv("SNOWFLAKE_HOME", "<The directory path where the toml file exists>") | ||
// os.Setenv("SNOWFLAKE_DEFAULT_CONNECTION_NAME", "<DSN Name>") | ||
|
||
db, err := sql.Open("snowflake", "autoConfig") | ||
if err != nil { | ||
log.Fatalf("failed to connect. %v,", err) | ||
} | ||
defer db.Close() | ||
query := "SELECT 1" | ||
rows, err := db.Query(query) | ||
if err != nil { | ||
log.Fatalf("failed to run a query. %v, err: %v", query, err) | ||
} | ||
defer rows.Close() | ||
var v int | ||
if !rows.Next() { | ||
log.Fatalf("no rows returned, expected 1") | ||
} | ||
err = rows.Scan(&v) | ||
if err != nil { | ||
log.Fatalf("failed to get result. err: %v", err) | ||
} | ||
if v != 1 { | ||
log.Fatalf("failed to get 1. got: %v", v) | ||
} | ||
|
||
if rows.Err() != nil { | ||
fmt.Printf("ERROR: %v\n", rows.Err()) | ||
return | ||
} | ||
fmt.Printf("Congrats! You have successfully run %v with Snowflake DB!\n", query) | ||
} |
Oops, something went wrong.