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

*gorm.DB和*query.Query混合使用的最佳实践 #7322

Open
Neightly opened this issue Dec 20, 2024 · 0 comments
Open

*gorm.DB和*query.Query混合使用的最佳实践 #7322

Neightly opened this issue Dec 20, 2024 · 0 comments
Assignees
Labels
type:question general questions

Comments

@Neightly
Copy link

Your Question

两者的文档都看过,gen的文档主要在于演示对于原生gorm的封装,展示各种便利性,并没有体现两者之间混合使用的场景。

一个实际的场景是:最初使用了gorm,后来渐进式使用gen替换一部分gorm,两者共同存在。
另外的使用场景是:数据库中有很多表,但是并不是生成在同一个目录下,因此会出现相互独立的model和query,各个query之间并不能相互沟通,仍然需要通过*gorm.DB。

存在的问题:通过*gorm.DB可以很方便的构建xxx/query.Query,但是反过来并不容易。
从API上看可以通过UnderlyingDB,但是只是类型正确,状态可能已经改变。在query中存在的Session/Transaction等操作导致UnderlyingDB给出的DB并不能保证就是当初的DB了,譬如xxx/query.Query已经处在了事务中,如何构建一个yyy/query.Query使其处于或者不处于xxx的事务中?

The document you expected this should be explained

Expected answer

@Neightly Neightly added the type:question general questions label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

2 participants