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

Only the last GroupBy() call will be used #74

Closed
ionling opened this issue Jun 15, 2022 · 2 comments
Closed

Only the last GroupBy() call will be used #74

ionling opened this issue Jun 15, 2022 · 2 comments

Comments

@ionling
Copy link

ionling commented Jun 15, 2022

When you call GroupBy() multiple times, only the last one will be in the SQL.

Code:

func (sb *SelectBuilder) GroupBy(col ...string) *SelectBuilder {
	sb.groupByCols = col
	sb.marker = selectMarkerAfterGroupBy
	return sb
}

Why not:

func (sb *SelectBuilder) GroupBy(col ...string) *SelectBuilder {
	sb.groupByCols = append(sb.groupByCols, col...)
	sb.marker = selectMarkerAfterGroupBy
	return sb
}
@huandu
Copy link
Owner

huandu commented Jun 15, 2022

Current API design enables us to update GROUP BY columns more than once. If we want to append more columns, we can simply append data to a cols slice and then call GroupBy(cols...).

@ionling
Copy link
Author

ionling commented Jun 16, 2022

The Where() method support multiple times calling, and I think we can keep the behavior of Where() and GroupBy() consistent. That will be better and convenient other than use append() function.

@huandu huandu closed this as completed in 0e6e16e Jun 23, 2022
SpencerC added a commit to datastax-ext/go-sqlbuilder that referenced this issue Nov 30, 2022
* ignore unexported fields that are not embedded structs

* fix huandu#74 [BREAKING CHANGE] Select#GroupBy and Select#OrderBy behavior change.

Previous, GroupBy and OrderBy only keep the columns in the last call. Now, all columns are kept.

* fix huandu#75 add Struct#Columns/ColumnsForTag and Struct#Values/ValuesForTag

* remove a call to StructField.IsExported as it is not in go1.13

* refs huandu#78 add new `fieldas` tag to set AS name for SELECT

* update docs

* fix huandu#81 refactory struct field parser to make fieldas correct in all cases

* Add Gitter badge

* Fix insert ignore for postgres and sqlite.

* fix test

Co-authored-by: Michał Dobaczewski <[email protected]>
Co-authored-by: Huan Du <[email protected]>
Co-authored-by: The Gitter Badger <[email protected]>
Co-authored-by: Zhong Ren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants