Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
feat: Remove default value option from column (#324)
Browse files Browse the repository at this point in the history
Closes #298
  • Loading branch information
roneli authored Jun 7, 2022
1 parent 8fcafe8 commit 33a4353
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 17 deletions.
15 changes: 0 additions & 15 deletions provider/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/cloudquery/cq-provider-sdk/stats"
"github.com/hashicorp/go-hclog"
"github.com/iancoleman/strcase"
"github.com/modern-go/reflect2"
segmentStats "github.com/segmentio/stats/v4"
"github.com/thoas/go-funk"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -419,25 +418,11 @@ func (e TableExecutor) resolveColumns(ctx context.Context, meta schema.ClientMet
} else {
diags = diags.Add(e.handleResolveError(meta, resource, err, diag.WithSummary("column resolver %q failed for table %q", c.Name, e.Table.Name)))
}

// TODO: double check logic here
if reflect2.IsNil(c.Default) {
continue
}
// Set default value if defined, otherwise it will be nil
if err := resource.Set(c.Name, c.Default); err != nil {
diags = diags.Add(fromError(err, diag.WithResourceName(e.ResourceName), diag.WithType(diag.INTERNAL),
diag.WithSummary("failed to set resource default value for %s@%s", e.Table.Name, c.Name)))
}
continue
}
e.Logger.Trace("resolving column value with path", "column", c.Name)
// base use case: try to get column with CamelCase name
v := funk.Get(resource.Item, strcase.ToCamel(c.Name), funk.WithAllowZero())
if v == nil {
e.Logger.Trace("using column default value", "column", c.Name, "default", c.Default)
v = c.Default
}
e.Logger.Trace("setting column value", "column", c.Name, "value", v)
if err := resource.Set(c.Name, v); err != nil {
diags = diags.Add(fromError(err, diag.WithResourceName(e.ResourceName), diag.WithType(diag.INTERNAL),
Expand Down
2 changes: 0 additions & 2 deletions provider/schema/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ type Column struct {
Type ValueType
// Description about column, this description is added as a comment in the database
Description string
// Default value if the resolver/default getting gets a nil value
Default interface{}
// Column Resolver allows to set you own data based on resolving this can be an API call or setting multiple embedded values etc'
Resolver ColumnResolver
// Ignore errors checks if returned error from column resolver should be ignored.
Expand Down

0 comments on commit 33a4353

Please sign in to comment.