Skip to content

Commit

Permalink
updates places to use consts for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Dec 2, 2024
1 parent 7322017 commit dade253
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
5 changes: 3 additions & 2 deletions backend/pkg/sqlconnect/sql-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
mgmtv1alpha1 "github.com/nucleuscloud/neosync/backend/gen/go/protos/mgmt/v1alpha1"
"github.com/nucleuscloud/neosync/backend/pkg/clienttls"
dbconnectconfig "github.com/nucleuscloud/neosync/backend/pkg/dbconnect-config"
sqlmanager_shared "github.com/nucleuscloud/neosync/backend/pkg/sqlmanager/shared"
tun "github.com/nucleuscloud/neosync/internal/sshtunnel"
"github.com/nucleuscloud/neosync/internal/sshtunnel/connectors/mssqltunconnector"
"github.com/nucleuscloud/neosync/internal/sshtunnel/connectors/mysqltunconnector"
Expand Down Expand Up @@ -53,7 +54,7 @@ func WithMysqlParseTimeDisabled() SqlConnectorOption {
// WithPostgresDriver overrides default postgres driver
func WithDefaultPostgresDriver() SqlConnectorOption {
return func(opts *sqlConnectorOptions) {
opts.postgresDriver = "postgres"
opts.postgresDriver = sqlmanager_shared.DefaultPostgresDriver
}
}

Expand All @@ -77,7 +78,7 @@ func (rc *SqlOpenConnector) NewDbFromConnectionConfig(cc *mgmtv1alpha1.Connectio
}

options := sqlConnectorOptions{
postgresDriver: "pgx",
postgresDriver: sqlmanager_shared.PostgresDriver,
}
for _, opt := range opts {
if opt != nil {
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/sqlmanager/postgres/postgres-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func (p *PostgresManager) GetTableRowCount(
whereClause *string,
) (int64, error) {
tableName := sqlmanager_shared.BuildTable(schema, table)
builder := goqu.Dialect(sqlmanager_shared.PostgresDriver)
builder := getGoquDialect()
sqltable := goqu.I(tableName)

query := builder.From(sqltable).Select(goqu.COUNT("*"))
Expand All @@ -873,7 +873,7 @@ func (p *PostgresManager) GetTableRowCount(
}

func getGoquDialect() goqu.DialectWrapper {
return goqu.Dialect("postgres")
return goqu.Dialect(sqlmanager_shared.DefaultPostgresDriver)
}

func BuildPgTruncateStatement(
Expand Down
7 changes: 4 additions & 3 deletions backend/pkg/sqlmanager/shared/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func ToConstraintType(constraintType string) (ConstraintType, error) {
}

const (
PostgresDriver = "pgx"
MysqlDriver = "mysql"
MssqlDriver = "sqlserver"
PostgresDriver = "pgx"
DefaultPostgresDriver = "postgres"
MysqlDriver = "mysql"
MssqlDriver = "sqlserver"
)

type BatchExecOpts struct {
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/sqlmanager/sql-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *SqlManager) NewSqlConnection(

func GetColumnOverrideAndResetProperties(driver string, cInfo *sqlmanager_shared.DatabaseSchemaRow) (needsOverride, needsReset bool, err error) {
switch driver {
case sqlmanager_shared.PostgresDriver, "postgres":
case sqlmanager_shared.PostgresDriver, sqlmanager_shared.DefaultPostgresDriver:
needsOverride, needsReset := sqlmanager_postgres.GetPostgresColumnOverrideAndResetProperties(cInfo)
return needsOverride, needsReset, nil
case sqlmanager_shared.MysqlDriver:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s *Service) GetConnectionDataStream(

table := sqlmanager_shared.BuildTable(req.Msg.Schema, req.Msg.Table)
// used to get column names
query, err := querybuilder.BuildSelectLimitQuery("postgres", table, 1)
query, err := querybuilder.BuildSelectLimitQuery(sqlmanager_shared.DefaultPostgresDriver, table, 1)
if err != nil {
return err
}
Expand All @@ -177,7 +177,7 @@ func (s *Service) GetConnectionDataStream(
return err
}

selectQuery, err := querybuilder.BuildSelectQuery("postgres", table, columnNames, nil)
selectQuery, err := querybuilder.BuildSelectQuery(sqlmanager_shared.DefaultPostgresDriver, table, columnNames, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/benthos/benthos-builder/builders/sql-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func getAdditionalJobMappings(
})
} else {
switch driver {
case "postgres":
case sqlmanager_shared.DefaultPostgresDriver, sqlmanager_shared.PostgresDriver:
transformer, err := getJmTransformerByPostgresDataType(info)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion worker/pkg/query-builder/insert-query-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetInsertBuilder(
}

switch driver {
case sqlmanager_shared.PostgresDriver, "postgres":
case sqlmanager_shared.PostgresDriver, sqlmanager_shared.DefaultPostgresDriver:
return &PostgresDriver{
driver: driver,
logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion worker/pkg/query-builder/query-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SubsetColumnConstraint struct {

func getGoquDialect(driver string) goqu.DialectWrapper {
if driver == sqlmanager_shared.PostgresDriver {
return goqu.Dialect("postgres")
return goqu.Dialect(sqlmanager_shared.DefaultPostgresDriver)
}
return goqu.Dialect(driver)
}
Expand Down

0 comments on commit dade253

Please sign in to comment.