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
database/gdb: scan zero value for google.protobuf.Timestamp #3571
Labels
bug
It is confirmed a bug, but don't worry, we'll handle it.
Comments
目前是这样实现的,不知道有没有更优雅的方式 func (s *sUser) GetById(ctx context.Context, uid uint64) (*pbentity.User, error) {
var (
user *entity.User
userPB *pbentity.User
)
// 从数据库中获取用户信息
err := dao.User.Ctx(ctx).Where(do.User{
Id: uid,
}).Scan(&user)
if user == nil {
return nil, gerror.NewCodef(gcode.CodeInvalidParameter, g.I18n().T(ctx, "{#user-not-found}"))
}
// 转换 pb 对象
if err := gconv.Struct(user, &userPB); err != nil {
return nil, gerror.NewCodef(gcode.CodeInternalError, g.I18n().T(ctx, "{#system-busy}"))
}
// 处理 pb 时间
userPB.CreateAt = timestamppb.New(user.CreateAt.Time)
userPB.UpdateAt = timestamppb.New(user.UpdateAt.Time)
return userPB, err
} |
This is currently possible, but I don’t know if there is a more elegant way. func (s *sUser) GetById(ctx context.Context, uid uint64) (*pbentity.User, error) {
var (
user *entity.User
userPB *pbentity.User
)
// Get user information from the database
err := dao.User.Ctx(ctx).Where(do.User{
Id: uid,
}).Scan(&user)
if user == nil {
return nil, gerror.NewCodef(gcode.CodeInvalidParameter, g.I18n().T(ctx, "{#user-not-found}"))
}
// Convert pb object
if err := gconv.Struct(user, &userPB); err != nil {
return nil, gerror.NewCodef(gcode.CodeInternalError, g.I18n().T(ctx, "{#system-busy}"))
}
// Process pb time
userPB.CreateAt = timestamppb.New(user.CreateAt.Time)
userPB.UpdateAt = timestamppb.New(user.UpdateAt.Time)
return userPB, err
} |
@zcyc 可以试试给字段实现一个json.Unmarshaler接口 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go version
go version go1.22.3 darwin/amd64
GoFrame version
v2.7.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
I run gf-demo-grpc and use PostgresSQL for database.
DDL is:
When i request the GetById method, scan the zero value for google.protobuf.Timestamp of pbentity.User
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: