Skip to content

Commit

Permalink
updated abiltiy to use custom type on relation
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Aug 23, 2024
1 parent cc0659e commit b7b7340
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion cmd/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ func (s *Service) buildHandlerIfNeeded(ruleOptions *options.Rule, dSQL *string)
}
handlerDSQL += fmt.Sprintf("$Nop($%v)", name)
*dSQL = handlerDSQL
*dSQL = handlerDSQL
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/inference/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s *Spec) AddRelation(name string, join *query.Join, spec *Spec, cardinalit
for _, item := range s.Type.columnFields {
available = append(available, item.Column.Name)
}
return fmt.Errorf("failed to rel field for %v, available: %v", relColumn, available)
return fmt.Errorf("failed to match rel field for %v, available: %v %v", relColumn, s.Type.Name, available)
}

keyField := spec.Type.ByColumn(refColumn)
Expand Down
6 changes: 3 additions & 3 deletions internal/translator/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ func (s *Service) updateViewSchema(aView *view.View, resource *Resource, cache d
relViewlet := resource.Rule.Viewlets.Lookup(rel.Of.View.Ref)
relView := &relViewlet.View.View
relSchema := relView.Schema
relView.SetResource(aView.GetResource())
rel.Of.View = *relView
relations = append(relations, rel)
if relSchema != nil && relSchema.Name != "" { //used has defined custom type, skip generation
continue
}
relSchema.Name = view.DefaultTypeName(relSchema.Name)
relView.SetResource(aView.GetResource())
rel.Of.View = *relView
relations = append(relations, rel)
if err = s.updateViewSchema(relView, resource, cache, registry, types, doc); err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion view/column/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ func readSinkColumns(ctx context.Context, db *sql.DB, table string) ([]sink.Colu
if err != nil {
return nil, err
}
columns, err := config.Columns(ctx, session, db, table)
columns, vErr := config.Columns(ctx, session, db, table)
if len(columns) == 0 && table != "" {
columns, err = inferColumnWithSQL(ctx, db, "SELECT * FROM "+table+" WHERE 1 = 0", []interface{}{}, map[string]sink.Column{})
}
if len(columns) == 0 {
return nil, vErr
}
return columns, err
}

Expand Down

0 comments on commit b7b7340

Please sign in to comment.