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

database/gdb: Scan, Array, Value deserialization enhancement #3977

Open
cyjaysong opened this issue Nov 27, 2024 · 1 comment
Open

database/gdb: Scan, Array, Value deserialization enhancement #3977

cyjaysong opened this issue Nov 27, 2024 · 1 comment
Labels
discuss We need discuss to make decision. feature help wanted planned This issue/proposal is planned into our next steps.

Comments

@cyjaysong
Copy link
Contributor

cyjaysong commented Nov 27, 2024

Description

目前Scan不支持将查询的某个字段结果直接反序列化至指定变量,如下:

案例表结构
type User struct {
	Id       int64
	Username string
	Balance  decimal.Decimal
      	State    bool
}

1、
var  balance decimal.Decimal
err := db.Model("user").Fields("balance").Where("id", 1).Scan(&balance)
2、
var  totalBalance decimal.Decimal
err := db.Model("user").FieldSum("balance").WhereIn("id", []int64{1,2,3,4,5}).Scan(&totalBalance)
3、
var  username string
err := db.Model("user").Fields("username").Where("id", 1).Scan(&username)
4、
var ids []int64
err := db.Model("user").Fields("id").Where("state", true).Scan(&ids)

我尝试过封装ValueScan,但是当需要承接数据的变量为基本数据类型的变量时还是存在问题,所以我关闭了这个PR

var  balance decimal.Decimal
val, err := db.Model("user").Fields("balance").Where("id", 1).Value()
val.Scan(&balance)  //此时,balance 能够获取到正确的值

var  id int64
val, err := db.Model("user").Fields("id").Where("id", 1).Where("state", true).Value()
err = val.Scan(&id)  //此时,id 不能能获取到正确的值,err不为空,不支持基本数据类型

Additional

No response

@Issues-translate-bot Issues-translate-bot changed the title database/gdb: Scan, Array, Value 反序列化增强 database/gdb: Scan, Array, Value deserialization enhancement Nov 27, 2024
@gqcn gqcn added discuss We need discuss to make decision. planned This issue/proposal is planned into our next steps. feature help wanted and removed enhancement labels Nov 27, 2024
Copy link

Hello @cyjaysong. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @cyjaysong。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss We need discuss to make decision. feature help wanted planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

No branches or pull requests

2 participants