Skip to content

Commit

Permalink
SNOW-1634712 Support for toml file connection configuration (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy authored Oct 17, 2024
1 parent 8224d28 commit 5eda091
Show file tree
Hide file tree
Showing 12 changed files with 774 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/tomlfileconnection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tomlfileconnection.go
16 changes: 16 additions & 0 deletions cmd/tomlfileconnection/Makefile
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
50 changes: 50 additions & 0 deletions cmd/tomlfileconnection/tomlfileconnection.go
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)
}
Loading

0 comments on commit 5eda091

Please sign in to comment.