-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support returning any from callbacks #1046
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1046 +/- ##
==========================================
+ Coverage 46.04% 46.16% +0.12%
==========================================
Files 11 11
Lines 1490 1499 +9
==========================================
+ Hits 686 692 +6
Misses 667 667
- Partials 137 140 +3
Continue to review full report at Codecov.
|
|
||
if typ.NumMethod() == 0 { | ||
return callbackRetAny, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for this part. But I'm not sure how to add a unit test for the callbackRetAny (I tested it manually end-to-end).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write a test that registers and uses such an aggregator, similar to this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a test.
Add test Fix test
callback.go
Outdated
@@ -353,13 +353,27 @@ func callbackRetNil(ctx *C.sqlite3_context, v reflect.Value) error { | |||
return nil | |||
} | |||
|
|||
func callbackRetAny(ctx *C.sqlite3_context, v reflect.Value) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be callbackRetGeneric
for consistency with callbackArgGeneric
. Or rename the other one to callbackArgAny
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted, thanks!
callback.go
Outdated
@@ -353,13 +353,27 @@ func callbackRetNil(ctx *C.sqlite3_context, v reflect.Value) error { | |||
return nil | |||
} | |||
|
|||
func callbackRetAny(ctx *C.sqlite3_context, v reflect.Value) error { | |||
cb, err := callbackRet(v.Elem().Type()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible that the callback returned nil
, in which case v.Elem()
will return the invalid value. Presumably that needs to translate to SQLite NULL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean I should have a check after the err check like
if cb == nil {
return nil
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be this:
if v.IsNil() {
C.sqlite3_result_null(ctx)
return nil
}
ve := v.Elem()
cb, err := callbackRet(ve.Type())
if err != nil {
return err
}
return cb(ctx, ve)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied, thank you!
@rittneje I'm okay to merge. |
Thanks folks! |
Feel free to take this over or close this or make suggestions or whatever!
Closes #1045