Skip to content

Commit

Permalink
fixup! feat: redshift sdk driver
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum committed Mar 22, 2024
1 parent b6f691a commit d0b611e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
12 changes: 11 additions & 1 deletion sqlconnect/internal/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package postgres
import (
"encoding/json"
"fmt"
"net/url"

"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/util"
)
Expand All @@ -29,7 +30,16 @@ func (c Config) ConnectionString() string {
if c.SSLMode != "" {
sslMode = c.SSLMode
}
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s sslmode=%s", c.Host, c.Port, c.DBName, c.User, c.Password, sslMode)
dsn := url.URL{
Scheme: DatabaseType,
User: url.UserPassword(c.User, c.Password),
Host: fmt.Sprintf("%s:%d", c.Host, c.Port),
Path: c.DBName,
}
values := dsn.Query()
values.Set("sslmode", sslMode)
dsn.RawQuery = values.Encode()
return dsn.String()
}

func (c *Config) Parse(input json.RawMessage) error {
Expand Down
33 changes: 33 additions & 0 deletions sqlconnect/internal/redshift/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package redshift_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"

"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/redshift"
)

func TestRedshiftSDKConfig(t *testing.T) {
// Create a new SDKConfig
config := redshift.SDKConfig{
ClusterIdentifier: "cluster-identifier",
Database: "database",
User: "user",
Region: "region",
AccessKeyID: "access-key-id",
SecretAccessKey: "secret",
SessionToken: "token",
}
configJSON, err := json.Marshal(&config)
require.NoError(t, err)
require.Equal(t, "sdk", gjson.GetBytes(configJSON, "type").String())

// Unmarshal the JSON back into a new SDKConfig
var newConfig redshift.SDKConfig
err = newConfig.Parse(configJSON)
require.NoError(t, err)
require.Equal(t, config, newConfig)
}
Binary file not shown.
21 changes: 3 additions & 18 deletions sqlconnect/internal/redshift/legacy_mappings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package redshift

import "encoding/json"

var legacyColumnTypeMappings = map[string]string{
"int": "int",
"int2": "int",
Expand Down Expand Up @@ -33,22 +31,9 @@ var legacyColumnTypeMappings = map[string]string{

// legacyJsonRowMapper maps a row's scanned column to a json object's field
func legacyJsonRowMapper(databaseTypeName string, value any) any {
switch databaseTypeName {
case "JSON":
fallthrough
case "JSONB":
switch v := value.(type) {
case []byte:
return json.RawMessage(v)

case string:
return json.RawMessage(v)
}
default:
switch v := value.(type) {
case []byte:
return string(v)
}
switch v := value.(type) {
case []byte:
return string(v)
}
return value
}

0 comments on commit d0b611e

Please sign in to comment.