Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1634712 Support for toml file connection configuration #1204

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
617a495
implemented toml connection config
sfc-gh-ext-simba-jy Aug 30, 2024
93fed7d
added testing toml file
sfc-gh-ext-simba-jy Aug 30, 2024
97d0ace
Merge branch 'SNOW-1634712' of https://github.com/snowflakedb/gosnowf…
sfc-gh-ext-simba-jy Aug 30, 2024
cc025d3
fix lint
sfc-gh-ext-simba-jy Aug 30, 2024
873f7b7
add comments
sfc-gh-ext-simba-jy Aug 31, 2024
0575096
fix lint
sfc-gh-ext-simba-jy Aug 31, 2024
be15d2e
add more testing cases
sfc-gh-ext-simba-jy Sep 5, 2024
f36fc27
fix
sfc-gh-ext-simba-jy Sep 5, 2024
1a79d15
add more testing
sfc-gh-ext-simba-jy Sep 5, 2024
a9825c5
fix lint
sfc-gh-ext-simba-jy Sep 6, 2024
7e67b83
fix error
sfc-gh-ext-simba-jy Sep 6, 2024
f68f8c9
replaced all if to assertX in the testing codes
sfc-gh-ext-simba-jy Sep 7, 2024
41b35ae
fix typos
sfc-gh-ext-simba-jy Sep 7, 2024
3d6151f
updated doc, add sample application
sfc-gh-ext-simba-jy Sep 9, 2024
a7e234f
add sample file
sfc-gh-ext-simba-jy Sep 9, 2024
234532a
added details and modified the file permission to unify
sfc-gh-ext-simba-jy Sep 9, 2024
84ba09d
remove var keywords
sfc-gh-ext-simba-jy Sep 10, 2024
9eeaaf3
fix error and refactored code
sfc-gh-ext-simba-jy Sep 10, 2024
4eaa365
add error
sfc-gh-ext-simba-jy Sep 10, 2024
54bf520
fix the file permission issue
sfc-gh-ext-simba-jy Sep 10, 2024
f7e1932
fix lint
sfc-gh-ext-simba-jy Sep 10, 2024
061445f
refactored
sfc-gh-ext-simba-jy Sep 10, 2024
54123eb
remove spaces
sfc-gh-ext-simba-jy Sep 10, 2024
9fcaaff
fix
sfc-gh-ext-simba-jy Sep 11, 2024
363fb30
fix error message
sfc-gh-ext-simba-jy Sep 12, 2024
3c880d0
lint fix
sfc-gh-ext-simba-jy Sep 12, 2024
d345463
add one more testing to read token from a file
sfc-gh-ext-simba-jy Sep 12, 2024
bc2f515
add mock token file
sfc-gh-ext-simba-jy Sep 12, 2024
2099982
add more testing cases
sfc-gh-ext-simba-jy Sep 12, 2024
3b2e086
moved the testing token file
sfc-gh-ext-simba-jy Sep 12, 2024
9dbe2ab
add copyright
sfc-gh-ext-simba-jy Sep 12, 2024
9c8c150
fix
sfc-gh-ext-simba-jy Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 58 additions & 0 deletions cmd/tomlfileconnection/tomlfileconnection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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"
"os"

sf "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>")

cfg, err := sf.LoadConnectionConfig()
if err != nil {
log.Fatalf("failed to create Config, err: %v", err)
}
dsn, err := sf.DSN(cfg)
if err != nil {
log.Fatalf("failed to create DSN from Config: %v, err: %v", cfg, err)
}

db, err := sql.Open("snowflake", dsn)
if err != nil {
log.Fatalf("failed to connect. %v, err: %v", dsn, err)
}
defer db.Close()
query := "SELECT 1"
rows, err := db.Query(query) // no cancel is allowed
if err != nil {
log.Fatalf("failed to run a query. %v, err: %v", query, err)
}
defer rows.Close()
var v int
for rows.Next() {
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
Loading