-
-
Notifications
You must be signed in to change notification settings - Fork 407
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: create rows columns and value from structs and slice by custom tag #280
base: master
Are you sure you want to change the base?
Conversation
Hello @Rennbon. That is a great addition. I noticed that you add a new dependency for testing here. Do you think you can rewrite the test cases using the vanilla testing package only as I'm not sure if there is a need to change that at the moment? |
您好,我已经收到您的邮件,我会尽快给您回复,祝您好运。
|
I wonder why you ask me :) Personally, I do use testify; but if this project does not use it yet and has the policy to avoid external testing libraries, I agree that introducing it there is not a good idea. |
Hey @AlekSi Sorry I tagged you wrongly. Glad to get some feedback though. |
OK |
@theodesp I removed testify and used reflect.DeepEqual to verify that it was as expected. |
2e690de
to
94ed2f6
Compare
Author: Rennbon <343688972@qq.com>
Author: Rennbon <343688972@qq.com>
@Rennbon Thank you. Will try to test it this week a bit more. |
Ok, hope to merge soon. |
@theodesp Is there anything wrong with this PR |
@l3pp4rd Is there a way to add this PR in Travis CI/CD pipeline please. It seems that I'm not able to see the test results in order to merge. Thank you. |
Those are utility functions. They don't have to be in the sqlmock core. They could be published as a separate package. |
From a usage perspective, this commit reduces mock writing complexity. |
} | ||
for i := 0; i < num; i++ { | ||
f := val.Type().Field(i) | ||
column := f.Tag.Get(tag) |
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.
This code allows to use JSON tags, but doesn't fully support them.
Examples of incorrectly handled values: "-", "data,omitempty".
I think that using JSON tags is a bad default.
// NewRowsFromInterface new Rows from struct or slice or array reflect with tagName | ||
// NOTE: arr/slice must be of the same type | ||
// tagName default "json" | ||
func NewRowsFromInterface(m interface{}, tagName string) (*Rows, 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.
Go has generics now. It would be better to have multiple functions with stronger typing.
NewRowsFromSlice
NewRowsFromStruct
@dolmen 这个库是Go 1.15的,不是所有引用库都会升级到1.18的 |
It's easier to develop