Skip to content

Commit

Permalink
Fix CLI build - remove cgo import (#3036)
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi authored Dec 12, 2024
1 parent 9115bb7 commit 3ee899a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
7 changes: 7 additions & 0 deletions backend/pkg/sqlmanager/shared/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,10 @@ type InitSchemaStatements struct {
Label string
Statements []string
}

type SelectQuery struct {
Query string

// If true, this query could return rows that violate foreign key constraints
IsNotForeignKeySafeSubset bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
bb_internal "github.com/nucleuscloud/neosync/internal/benthos/benthos-builder/internal"
"github.com/nucleuscloud/neosync/internal/gotypeutil"
"github.com/nucleuscloud/neosync/internal/testutil"
querybuilder "github.com/nucleuscloud/neosync/worker/pkg/query-builder2"
"github.com/nucleuscloud/neosync/worker/pkg/workflows/datasync/activities/shared"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -89,8 +88,8 @@ func Test_ProcessorConfigEmpty(t *testing.T) {
"name": &mgmtv1alpha1.JobMappingTransformer{},
},
}
queryMap := map[string]map[tabledependency.RunType]*querybuilder.SelectQuery{
"public.users": {tabledependency.RunTypeInsert: &querybuilder.SelectQuery{Query: ""}},
queryMap := map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery{
"public.users": {tabledependency.RunTypeInsert: &sqlmanager_shared.SelectQuery{Query: ""}},
}
runconfigs := []*tabledependency.RunConfig{
tabledependency.NewRunConfig("public.users", tabledependency.RunTypeInsert, []string{"id"}, nil, []string{"id", "name"}, []string{"id", "name"}, []*tabledependency.DependsOn{}, nil, false),
Expand Down Expand Up @@ -186,8 +185,8 @@ func Test_ProcessorConfigEmptyJavascript(t *testing.T) {
tabledependency.NewRunConfig("public.users", tabledependency.RunTypeInsert, []string{"id"}, nil, []string{"id", "name"}, []string{"id", "name"}, []*tabledependency.DependsOn{}, nil, false),
}

queryMap := map[string]map[tabledependency.RunType]*querybuilder.SelectQuery{
"public.users": {tabledependency.RunTypeInsert: &querybuilder.SelectQuery{Query: ""}},
queryMap := map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery{
"public.users": {tabledependency.RunTypeInsert: &sqlmanager_shared.SelectQuery{Query: ""}},
}
logger := testutil.GetTestLogger(t)
connectionId := uuid.NewString()
Expand Down
3 changes: 1 addition & 2 deletions internal/benthos/benthos-builder/builders/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
bb_shared "github.com/nucleuscloud/neosync/internal/benthos/benthos-builder/shared"
connectionmanager "github.com/nucleuscloud/neosync/internal/connection-manager"
neosync_benthos "github.com/nucleuscloud/neosync/worker/pkg/benthos"
querybuilder "github.com/nucleuscloud/neosync/worker/pkg/query-builder2"
"github.com/nucleuscloud/neosync/worker/pkg/workflows/datasync/activities/shared"
)

Expand Down Expand Up @@ -166,7 +165,7 @@ func buildBenthosSqlSourceConfigResponses(
groupedTableMapping map[string]*tableMapping,
runconfigs []*tabledependency.RunConfig,
dsnConnectionId string,
tableRunTypeQueryMap map[string]map[tabledependency.RunType]*querybuilder.SelectQuery,
tableRunTypeQueryMap map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery,
groupedColumnInfo map[string]map[string]*sqlmanager_shared.DatabaseSchemaRow,
tableDependencies map[string][]*sqlmanager_shared.ForeignConstraint,
colTransformerMap map[string]map[string]*mgmtv1alpha1.JobMappingTransformer,
Expand Down
3 changes: 1 addition & 2 deletions internal/benthos/benthos-builder/shared/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

sqlmanager_shared "github.com/nucleuscloud/neosync/backend/pkg/sqlmanager/shared"
tabledependency "github.com/nucleuscloud/neosync/backend/pkg/table-dependency"
querybuilder "github.com/nucleuscloud/neosync/worker/pkg/query-builder2"
)

// Holds the environment variable name and the connection id that should replace it at runtime when the Sync activity is launched
Expand All @@ -28,7 +27,7 @@ type SelectQueryMapBuilder interface {
runConfigs []*tabledependency.RunConfig,
subsetByForeignKeyConstraints bool,
groupedColumnInfo map[string]map[string]*sqlmanager_shared.DatabaseSchemaRow,
) (map[string]map[tabledependency.RunType]*querybuilder.SelectQuery, error)
) (map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery, error)
}

func WithEnvInterpolation(input string) string {
Expand Down
8 changes: 4 additions & 4 deletions worker/pkg/query-builder2/subset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func BuildSelectQueryMap(
runConfigs []*tabledependency.RunConfig,
subsetByForeignKeyConstraints bool,
groupedColumnInfo map[string]map[string]*sqlmanager_shared.DatabaseSchemaRow,
) (map[string]map[tabledependency.RunType]*SelectQuery, error) {
) (map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery, error) {
tableDependencies := map[string]*TableConstraints{}
for _, rc := range runConfigs {
if rc.RunType() != tabledependency.RunTypeInsert {
Expand Down Expand Up @@ -56,17 +56,17 @@ func BuildSelectQueryMap(
qb.AddWhereCondition(schema, table, qualifiedWhereCaluse)
}

querymap := map[string]map[tabledependency.RunType]*SelectQuery{}
querymap := map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery{}
for _, cfg := range runConfigs {
if _, ok := querymap[cfg.Table()]; !ok {
querymap[cfg.Table()] = map[tabledependency.RunType]*SelectQuery{}
querymap[cfg.Table()] = map[tabledependency.RunType]*sqlmanager_shared.SelectQuery{}
}
schema, table := splitTable(cfg.Table())
query, _, isNotForeignKeySafe, err := qb.BuildQuery(schema, table)
if err != nil {
return nil, err
}
querymap[cfg.Table()][cfg.RunType()] = &SelectQuery{
querymap[cfg.Table()][cfg.RunType()] = &sqlmanager_shared.SelectQuery{
Query: query,
IsNotForeignKeySafeSubset: isNotForeignKeySafe,
}
Expand Down
9 changes: 1 addition & 8 deletions worker/pkg/query-builder2/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@ import (
// QueryMapBuilderWrapper implements the SelectQueryMapBuilder interface
type QueryMapBuilderWrapper struct{}

type SelectQuery struct {
Query string

// If true, this query could return rows that violate foreign key constraints
IsNotForeignKeySafeSubset bool
}

// BuildSelectQueryMap wraps the original BuildSelectQueryMap function
func (w *QueryMapBuilderWrapper) BuildSelectQueryMap(
driver string,
runConfigs []*tabledependency.RunConfig,
subsetByForeignKeyConstraints bool,
groupedColumnInfo map[string]map[string]*sqlmanager_shared.DatabaseSchemaRow,
) (map[string]map[tabledependency.RunType]*SelectQuery, error) {
) (map[string]map[tabledependency.RunType]*sqlmanager_shared.SelectQuery, error) {
return BuildSelectQueryMap(
driver,
runConfigs,
Expand Down

0 comments on commit 3ee899a

Please sign in to comment.