Skip to content

Commit

Permalink
fix redshift example
Browse files Browse the repository at this point in the history
Signed-off-by: Yuvraj <founder@datasherlock.io>
  • Loading branch information
Yuvraj committed May 17, 2024
1 parent 5d31fde commit 091cce5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
13 changes: 10 additions & 3 deletions databases/redshift/redshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import (
"database/sql"
"encoding/json"
"fmt"
"os"
"strings"

_ "github.com/mashiike/redshift-data-sql-driver"
_ "github.com/lib/pq"
"github.com/thesaas-company/xray/config"
"github.com/thesaas-company/xray/types"
)

// DB_PASSWORD is the environment variable that holds the database password.
var DB_PASSWORD = "DB_PASSWORD"

const (
Redshift_Schema_query = "SHOW COLUMNS FROM TABLE %s.%s.%s;"
Redshift_Tables_query = "SELECT * FROM svv_all_tables WHERE database_name = '%s';"
Expand All @@ -30,9 +34,12 @@ func NewRedshift(client *sql.DB) (types.ISQL, error) {
}

func NewRedshiftWithConfig(cfg *config.Config) (types.ISQL, error) {
if os.Getenv(DB_PASSWORD) == "" || len(os.Getenv(DB_PASSWORD)) == 0 {
return nil, fmt.Errorf("please set %s env variable for the database", DB_PASSWORD)
}
DB_PASSWORD = os.Getenv(DB_PASSWORD)

Check warning on line 40 in databases/redshift/redshift.go

View check run for this annotation

Codecov / codecov/patch

databases/redshift/redshift.go#L37-L40

Added lines #L37 - L40 were not covered by tests

dsn := fmt.Sprintf("arn:aws:secretsmanager:%s:%s:secret:%s", cfg.Region, cfg.AccountID, cfg.SecretName)
db, err := sql.Open("redshift-data", dsn)
db, err := sql.Open("postgres", fmt.Sprintf("host=%s port=%v user=%s password=%s dbname=%s sslmode=%s", cfg.Host, cfg.Port, cfg.Username, DB_PASSWORD, cfg.DatabaseName, cfg.SSL))

Check warning on line 42 in databases/redshift/redshift.go

View check run for this annotation

Codecov / codecov/patch

databases/redshift/redshift.go#L42

Added line #L42 was not covered by tests
if err != nil {
return nil, fmt.Errorf("error creating a new session : %v", err)
}
Expand Down
10 changes: 6 additions & 4 deletions example/redshift/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
func main() {
// Define the configuration for the Redshift instance
cfg := &config.Config{
Region: "my-region-us-west-2",
AccountID: "123456789012",
SecretName: "my-secret",
Host: "default-workgroup.609973658768.ap-south-1.redshift-serverless.amazonaws.com",
DatabaseName: "dev",
Username: "admin",
Port: "5439",
SSL: "require",

Check warning on line 19 in example/redshift/main.go

View check run for this annotation

Codecov / codecov/patch

example/redshift/main.go#L15-L19

Added lines #L15 - L19 were not covered by tests
}

// Create a new Redshift instance
Expand Down Expand Up @@ -54,7 +56,7 @@ func main() {
res := rs.GenerateCreateTableQuery(table)
fmt.Println(res)

query := "SELECT * FROM my_table"
query := "SELECT * FROM sales limit 10"

Check warning on line 59 in example/redshift/main.go

View check run for this annotation

Codecov / codecov/patch

example/redshift/main.go#L59

Added line #L59 was not covered by tests
result, err := rs.Execute(query)
if err != nil {
fmt.Printf("Error executing query: %v\n", err)
Expand Down
7 changes: 0 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/go-sql-driver/mysql v1.8.1
github.com/lib/pq v1.10.9
github.com/mashiike/redshift-data-sql-driver v0.2.0
github.com/sirupsen/logrus v1.9.3
github.com/snowflakedb/gosnowflake v1.10.0
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -34,21 +33,15 @@ require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.39 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.37 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.59 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.42 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.0 // indirect
github.com/aws/aws-sdk-go-v2/service/redshiftdata v1.20.5 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.31.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect
github.com/aws/smithy-go v1.14.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 h1:CdzPW9kKi
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35/go.mod h1:QGF2Rs33W5MaN9gYdEQOBBFPLwTZkEhRwI33f7KIG0o=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.0 h1:e2ooMhpYGhDnBfSvIyusvAwX7KexuZaHbQY2Dyei7VU=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.0/go.mod h1:bh2E0CXKZsQN+faiKVqC40vfNMAWheoULBCnEgO9K+8=
github.com/aws/aws-sdk-go-v2/service/redshiftdata v1.20.5 h1:iIRfLBX36lMn7vXdaVF1PZV/jiBXeUpiL2KHkGOjVsc=
github.com/aws/aws-sdk-go-v2/service/redshiftdata v1.20.5/go.mod h1:q++QEMyKK3FcyuHOuab73F3mtkmP/Xu25VkMSEgqpE0=
github.com/aws/aws-sdk-go-v2/service/s3 v1.31.0 h1:B1G2pSPvbAtQjilPq+Y7jLIzCOwKzuVEl+aBBaNG0AQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.31.0/go.mod h1:ncltU6n4Nof5uJttDtcNQ537uNuwYqsZZQcpkd2/GUQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.6/go.mod h1:Y1VOmit/Fn6Tz1uFAeCO6Q7M2fmfXSCLeL5INVYsLuY=
Expand Down Expand Up @@ -460,8 +458,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mashiike/redshift-data-sql-driver v0.2.0 h1:agU0/gcS0aiznmJwTbru14yDSKOi9dPU/wDGFean7hc=
github.com/mashiike/redshift-data-sql-driver v0.2.0/go.mod h1:VwxNm3Jlf4EM8r2lSPYCJ7MnNTSjiQzi83KXRXMzJPE=
github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs=
github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand Down

0 comments on commit 091cce5

Please sign in to comment.