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

dao现在还不能设置 context,要如何安全的操作 #18

Closed
zundaren opened this issue Feb 9, 2023 · 5 comments
Closed

dao现在还不能设置 context,要如何安全的操作 #18

zundaren opened this issue Feb 9, 2023 · 5 comments

Comments

@zundaren
Copy link

zundaren commented Feb 9, 2023

如果获取 db设置 context再次设置到 dao,这会有问题
gplus.Init(dao.Db().WithContext(ctx))

接口操作
第一次不设置context save操作
第二次设置 context get操作

再次调用接口结果context canceled

@afumu
Copy link
Member

afumu commented Feb 9, 2023

具体可以看看gorm的文档,应该不是gorm-plus的问题

@zundaren
Copy link
Author

zundaren commented Feb 9, 2023

具体可以看看gorm的文档,应该不是gorm-plus的问题

应该是 db clone的问题,你的dao操作都是同一个db,如果修改了 db 其他的操作会有影响

@afumu
Copy link
Member

afumu commented Feb 9, 2023

具体可以看看gorm的文档,应该不是gorm-plus的问题

应该是 db clone的问题,你的dao操作都是同一个db,如果修改了 db 其他的操作会有影响

哦哦,我理解你的意思了,我找个时间改一下,或者你有时间的话,也可以研究一下怎么改比较好,提个pr上来

@zundaren
Copy link
Author

具体可以看看gorm的文档,应该不是gorm-plus的问题

应该是 db clone的问题,你的dao操作都是同一个db,如果修改了 db 其他的操作会有影响

哦哦,我理解你的意思了,我找个时间改一下,或者你有时间的话,也可以研究一下怎么改比较好,提个pr上来

image

image

大佬,我在 dao里面设置db属性,每次操作context生成新的 dao,测试了下功能都正常,context 也没错乱,就是不知道每次新生成的 dao 会不会有什么性能问题

@afumu afumu closed this as completed Feb 15, 2023
@0x457
Copy link

0x457 commented Nov 2, 2023

期待函数签名 增加context

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

No branches or pull requests

3 participants