We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
运行示例代码,如果把user对应的age和uid属性调换一下时,即使绑定了对应的tag,但是仍然按照数据库中顺序进行赋值,数据库的第一列uid对应的了user类的第一个属性age
The text was updated successfully, but these errors were encountered:
在源码中session.go的scanStructAll函数中,rows.Scan(sfs...)这一行调试发现,运行之后对应的sfs和s.IBinder.BindResult对应的变量直接按照数据库查询的列顺序绑定了值,未按照tag进行比对,不知道是不是feature还是bug
Sorry, something went wrong.
在orm中, 其实是先解析struct, 再把解析的字段用于查询, 所以, 会造成这种结果. 而这个原生查询绑定是外挂到原生查询的, 所以, 要按照struct顺序才行, 这个是database/sql底层所决定的, 也就是需要人工手动指定的 原生查询是
... var field1 stirng var field2 int rows.scan(&field1, &field2) ...
从这个原生构造中就可以看出, 程序自己是无法确定哪个字段的, 除非舍弃一定的性能, 先把rows.scan绑定到map, 然后再用map去映射, 即可解决顺序问题, 这里需要额外浪费一倍的空间和性能
gorose在这里做了取舍, 用了手动指定顺序, 看来需要在文档里说明一下, 免得造成疑惑
No branches or pull requests
运行示例代码,如果把user对应的age和uid属性调换一下时,即使绑定了对应的tag,但是仍然按照数据库中顺序进行赋值,数据库的第一列uid对应的了user类的第一个属性age
The text was updated successfully, but these errors were encountered: