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

[Feature Request] Concrete type WhereIn helpers #344

Closed
shousper opened this issue Jul 16, 2018 · 7 comments
Closed

[Feature Request] Concrete type WhereIn helpers #344

shousper opened this issue Jul 16, 2018 · 7 comments

Comments

@shousper
Copy link

We have methods that accept 1 or more lists of values for certain queries, a simple example might be something like this:

func (r *someRepository) FindAllByTypes(ctx context.Context, types []interface{}) ([]*persistence.Client, error) {
	return persistence.Clients(qm.WhereIn("type in ?", types...)).All(ctx, r.db)
}

But.. the types aren't interfaces, they're often just strings or UUIDs, sometimes ints or enums. So we need to write a helper to convert our concrete slices to interface{} an slice. We can't use varargs, because the input values aren't hard-coded or fixed length.

Would it be worth the query mod system supporting these concrete types somehow? Maybe not WhereInString but rather WhereIn("type in ?", qm.InStrings(types)) or maybe the Where could be more powerful by accepting a parameter implementing an In interface of some sort instead?

I understand this would probably look like a breaking change, but I'm hoping you've already got some ideas on this? 😃

@aarondl
Copy link
Member

aarondl commented Jul 16, 2018

First of all I'm not 100% sure why this would be a breaking change. Sounds like you just want some extra helpers to convert say []string -> []interface{} and []int -> []interface{} etc. No?

@shousper
Copy link
Author

Spot on @aarondl.

@louis77
Copy link

louis77 commented Nov 2, 2018

Something like that:

        names := []string{"bernd", "werner", "urs"}
	namesInterface := make([]interface{}, len(names))
	for i, v := range names {
		namesInterface[i] = v
	}

@shousper
Copy link
Author

shousper commented Nov 8, 2018

@aarondl, I guess the breaking change comment was if changes were made to the Where function. I think a simple helper might be enough for now 👌

@aarondl
Copy link
Member

aarondl commented Jan 2, 2019

This will be superceded by #426

@aarondl aarondl closed this as completed Jan 2, 2019
@shousper
Copy link
Author

Not sure where to comment as both issues are closed, but I just realised #426 never actually implemented a helper for the IN operator.

Any chance of this getting re-opened until that's done?

Cheers.

@aarondl
Copy link
Member

aarondl commented Jul 13, 2019

@shousper There's been a separate feature request for them opened here: #570

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

No branches or pull requests

3 participants