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

Count to Counts with MultiValue and Count fixed #352

Merged
merged 20 commits into from
Aug 4, 2019

Conversation

kediboregi
Copy link
Contributor

so i can use count without group by and counts with group by

@drujensen
Copy link
Member

drujensen commented Jul 31, 2019

@unequaled86 Thanks for the contribution.

Can you provide some details as to why you want this change? I have never seen counts used before and doesn't really roll off the tongue for me.

Also, its kinda frowned on to have two methods do the same thing. Please change my mind. ;-)

nm, It looks like counts is returning multiple values based on the group by clause. Is this correct?

@kediboregi
Copy link
Contributor Author

kediboregi commented Aug 1, 2019

page = 2
limit = 10

 # its add_aggregate_field for group by
posts.where(:title, :like, "%#{search_text}")

 # (already not working with where bc db.query_one)
count = posts.count.run

# pagination
posts.limit(limit)
posts.offset((page - 1)*limit)
results = posts.select

{"results" => results, "pages_size" => count.fdiv(limit).ceil.to_i, "posts_size" => count.to_i}.to_json

in that rest api scenario
it was giving error because of group by clause on count with db.query_one, unable to use with
where. also i need single value count with where method without group by
i created counts its fixed version of old count
deleted group_by from count
so we can use count for that scenario without and group by counts with group by
fast reasonable solution

maybe we can change count method with additional parameters like a add group_by to sql and always multivalue in the future

@drujensen
Copy link
Member

drujensen commented Aug 1, 2019

@unequaled86 ok. Thanks for the explanation.

I'm not a fan of the counts. I recommend finding a way to get count to work with and without a group_by.

Is this something you would be interested in looking into?

@kediboregi
Copy link
Contributor Author

@drujensen rewrited and its look like acceptable

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

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

Group By should not be automatically added to the count. Only if a user specifies one should it be included. Let's just remove it for now.

spec/granite/query/assemblers/mysql_spec.cr Outdated Show resolved Hide resolved
spec/granite/query/assemblers/mysql_spec.cr Outdated Show resolved Hide resolved
spec/granite/query/assemblers/sqlite_spec.cr Outdated Show resolved Hide resolved
src/granite/query/assemblers/base.cr Outdated Show resolved Hide resolved
Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

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

Much better! I prefer group_by over group but let me know what you think.

docs/querying.md Outdated Show resolved Hide resolved
docs/querying.md Outdated Show resolved Hide resolved
spec/granite/query/assemblers/mysql_spec.cr Outdated Show resolved Hide resolved
docs/querying.md Outdated Show resolved Hide resolved
@Blacksmoke16
Copy link
Contributor

Minor, but you should run crystal tool format as well. Standard is to use spaces vs tabs for indentation.

@drujensen
Copy link
Member

hmm, I see what you mean. Rails uses order and group_by. I think it's ok to follow their lead.

@kediboregi
Copy link
Contributor Author

i run crystal tool format before commit
i can change it to group_by

@Blacksmoke16
Copy link
Contributor

i run crystal tool format before commit

Perfect, could you update the tabs to use spaces? Guess it doesn't do that for you.

@kediboregi
Copy link
Contributor Author

kediboregi commented Aug 1, 2019

i run crystal tool format before commit

Perfect, could you update the tabs to use spaces? Guess it doesn't do that for you.

i did now

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

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

nice work. update the documentation and add a couple more specs for group_by. maybe include a test for chaining multiple group_by as well. Post.group_by(:name).group_by(:age)

docs/querying.md Outdated Show resolved Hide resolved
spec/granite/query/assemblers/mysql_spec.cr Show resolved Hide resolved
src/granite/query/builder.cr Show resolved Hide resolved
Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

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

💯

docs/crud.md Outdated Show resolved Hide resolved
@drujensen
Copy link
Member

drujensen commented Aug 3, 2019

@unequaled86 hate to do this to you but we merged a large breaking change #346 that is causing issues in this PR. Can you take a look?

@kediboregi
Copy link
Contributor Author

kediboregi commented Aug 3, 2019

fixed, please merge it before happen new issues .d

@drujensen drujensen merged commit 9a2d4fe into amberframework:master Aug 4, 2019
@drujensen
Copy link
Member

@unequaled86 Thank you

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.

3 participants