diff --git a/sqlconnect/internal/postgres/config.go b/sqlconnect/internal/postgres/config.go index 12fd17a..bd49480 100644 --- a/sqlconnect/internal/postgres/config.go +++ b/sqlconnect/internal/postgres/config.go @@ -3,6 +3,7 @@ package postgres import ( "encoding/json" "fmt" + "net/url" "github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/util" ) @@ -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 { diff --git a/sqlconnect/internal/redshift/config_test.go b/sqlconnect/internal/redshift/config_test.go new file mode 100644 index 0000000..de86fbb --- /dev/null +++ b/sqlconnect/internal/redshift/config_test.go @@ -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) +} diff --git a/sqlconnect/internal/redshift/driver/__debug_bin2748135260 b/sqlconnect/internal/redshift/driver/__debug_bin2748135260 deleted file mode 100755 index 1582794..0000000 Binary files a/sqlconnect/internal/redshift/driver/__debug_bin2748135260 and /dev/null differ diff --git a/sqlconnect/internal/redshift/legacy_mappings.go b/sqlconnect/internal/redshift/legacy_mappings.go index 722f153..9fec981 100644 --- a/sqlconnect/internal/redshift/legacy_mappings.go +++ b/sqlconnect/internal/redshift/legacy_mappings.go @@ -1,7 +1,5 @@ package redshift -import "encoding/json" - var legacyColumnTypeMappings = map[string]string{ "int": "int", "int2": "int", @@ -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 }