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

Returning func be able to handle nil #140

Closed
randallmlough opened this issue Aug 21, 2019 · 2 comments
Closed

Returning func be able to handle nil #140

randallmlough opened this issue Aug 21, 2019 · 2 comments
Assignees

Comments

@randallmlough
Copy link

randallmlough commented Aug 21, 2019

Is your feature request related to a problem? Please describe.
It would be nice if Returning function could be nil and if so act is if it's not there.

I use your (awesome) library as a helper func to build queries across my application. In some cases I want to return values like an id or the whole updated row, but then sometimes I don't need to. It doesn't make a lot of sense to create additional logic just for a Returning stmt.

Note: The desired behavior works if the Returning func isn't passed any values .Returning() but if you pass it the value of nil it panics (because of reflect). As a result since this returning clause is in a helper func it will always be passed some value, even if it's just nil.

Describe the solution you'd like
Maybe a check before reflect is run?

func (ud *UpdateDataset) Returning(returning ...interface{}) *UpdateDataset {
	if isNil(returning){
              return ud
        }
	// continue...
}
func isNil(v interface{}) bool {
	switch t := v.(type) {
	case []interface{}:
		if len(t) <= 0 || (len(t) == 1 && t[0] == nil){
			return true
		}
	default:
		if t == nil {
			return true
		}
	}
	return false
}
@doug-martin
Copy link
Owner

This should be fixed by #142. Ill update and close once published.

doug-martin added a commit that referenced this issue Aug 22, 2019
doug-martin added a commit that referenced this issue Aug 22, 2019
@doug-martin
Copy link
Owner

Just published! Let me know if you have any more issues.

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