Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Each updateFilter must have corresponding bindPlan #373

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pbberlin
Copy link

Current behavior:

I set an updateFilter - then I update => works.
Now I remove the updateFilter - then I update => broken - still only the columns from previous updateFilter are updated. Reason: the bindPlan does not reflect the removal of the update filter.

I added tests, to demonstrate the fixed behavior.

Kind regards
Peter

colFilter = acceptAllFilter
} else {
t.updatePlan = bindPlan{} // a new bindPlan everytime; since we cannot compare colFilter funcs
t.colFilter = colFilter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a firm believer in avoiding else at nearly all costs. Branches are really harsh on the mental stack when reading code, and else statements are the worst (especially in go, where they can carry extra context). Can we try something more like:

if t.colFilter != nil || colFilter != nil {
    t.updatePlan = bindPlan{}
}
if colFilter == nil {
    colFilter = acceptAllFilter
}
t.colFilter = colFilter

@@ -26,12 +26,13 @@ type TableMap struct {
SchemaName string
gotype reflect.Type
Columns []*ColumnMap
keys []*ColumnMap
keys []*ColumnMap // primary key column; can be autoIncrement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is related to this PR.

@@ -296,7 +296,7 @@ func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey
isPK = true
case "autoincrement":
isAuto = true
case "notnull":
case "notnull", "not null":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not related to this PR, and it also doesn't have any tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants