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

Add method to update (one or multiple rows) specifying the columns to be updated #437

Merged

Conversation

gustavotero7
Copy link
Contributor

@gustavotero7 gustavotero7 commented Sep 8, 2019

Summary

Some times we need to specify the column name(s) when updating a row, it's more useful than specifying the columns to be ignored when we have big models and want to update only a few fields.

Usage

...
    user.Email = "rick@example.com"
    if err := tx.UpdateColumns(&user, "email"); err != nil {
        log.Print(err)
    }
...

Tests

SODA_DIALECT=sqlite go test -cover -tags "sqlite" ./...
ok  	github.com/gobuffalo/pop	2.237s	coverage: 60.9% of statements
ok  	github.com/gobuffalo/pop/associations	(cached)	coverage: 47.6% of statements
ok  	github.com/gobuffalo/pop/columns	(cached)	coverage: 89.0% of statements
ok  	github.com/gobuffalo/pop/fix	(cached)	coverage: 93.5% of statements
ok  	github.com/gobuffalo/pop/genny/config	(cached)	coverage: 100.0% of statements
ok  	github.com/gobuffalo/pop/genny/fizz/cempty	(cached)	coverage: 82.1% of statements
ok  	github.com/gobuffalo/pop/genny/fizz/ctable	(cached)	coverage: 78.8% of statements
ok  	github.com/gobuffalo/pop/genny/model	0.971s	coverage: 90.1% of statements
ok  	github.com/gobuffalo/pop/internal/defaults	(cached)	coverage: 100.0% of statements
?   	github.com/gobuffalo/pop/internal/oncer	[no test files]
ok  	github.com/gobuffalo/pop/internal/randx	(cached)	coverage: 100.0% of statements
?   	github.com/gobuffalo/pop/logging	[no test files]
ok  	github.com/gobuffalo/pop/nulls	(cached)	coverage: 0.0% of statements
?   	github.com/gobuffalo/pop/packrd	[no test files]
ok  	github.com/gobuffalo/pop/slices	(cached)	coverage: 29.4% of statements
?   	github.com/gobuffalo/pop/soda	[no test files]
ok  	github.com/gobuffalo/pop/soda/cmd	(cached)	coverage: 23.3% of statements
ok  	github.com/gobuffalo/pop/soda/cmd/generate	1.201s	coverage: 33.1% of statements
?   	github.com/gobuffalo/pop/soda/cmd/schema	[no test files]

@gustavotero7 gustavotero7 requested a review from a team as a code owner September 8, 2019 23:15
Copy link
Member

@mclark4386 mclark4386 left a comment

Choose a reason for hiding this comment

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

Looks great! Would you mind improving the test coverage on it a bit (mainly thinking about giving more than one column name to update)?

@gustavotero7
Copy link
Contributor Author

Looks great! Would you mind improving the test coverage on it a bit (mainly thinking about giving more than one column name to update)?

Hi, @mclark4386 Thanks 😃
I have added a couple of tests to cover more scenarios, let me know WDYT.

@gustavotero7
Copy link
Contributor Author

Hi guys, any update on this? @mclark4386 @stanislas-m

Copy link
Member

@mclark4386 mclark4386 left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the tweaks and fuller testing!

@stanislas-m stanislas-m merged commit c21e5c8 into gobuffalo:development Oct 2, 2019
@gustavotero7 gustavotero7 deleted the feature/update-columns branch December 1, 2019 22:30
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.

None yet

3 participants