go-gorm / gen

Gen: Friendly & Safer GORM powered by Code Generation
https://gorm.io/gen/
MIT License
2.23k stars 293 forks source link

get db from `query.Query` #1221

Closed trim21 closed 5 days ago

trim21 commented 5 days ago

Describe the feature

There are some case it's hard to write a sql with generated query builder, it also doesn't need to get return value, so it's more reasonable to just use db.Exec.

Is is possible to get db from query.Query so we can execute some raw sql?

Normally we can just use gorm.DB, but when in txn (q.Transaction(func(tx *query.Query) error {})), we should get db from Query.

Motivation

Related Issues

trim21 commented 5 days ago

I just realize I can add new method in generated files to get private field.