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

Support returning any from callbacks #1046

Merged
merged 4 commits into from May 30, 2022

Conversation

eatonphil
Copy link
Contributor

@eatonphil eatonphil commented May 13, 2022

Feel free to take this over or close this or make suggestions or whatever!

Closes #1045

@codecov-commenter
Copy link

codecov-commenter commented May 13, 2022

Codecov Report

Merging #1046 (12637a6) into master (aa1e904) will increase coverage by 0.12%.
The diff coverage is 44.44%.

@@            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     
Impacted Files Coverage Δ
callback.go 58.53% <44.44%> (+0.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa1e904...12637a6. Read the comment docs.


if typ.NumMethod() == 0 {
return callbackRetAny, nil
}
Copy link
Contributor Author

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).

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a 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 {
Copy link
Collaborator

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.

Copy link
Contributor Author

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())
Copy link
Collaborator

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.

Copy link
Contributor Author

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
}

?

Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied, thank you!

@mattn
Copy link
Owner

mattn commented May 28, 2022

@rittneje I'm okay to merge.

@rittneje rittneje merged commit 3ccccfb into mattn:master May 30, 2022
@eatonphil eatonphil deleted the pe/return-any branch May 30, 2022 08:25
@eatonphil
Copy link
Contributor Author

Thanks folks!

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.

Aggregator Done() can't return any/interface{}
4 participants