add request id to sql query log

This commit is contained in:
MaysWind
2023-09-03 13:54:07 +08:00
parent 6b30a0aebc
commit 9221f3fc96
23 changed files with 432 additions and 360 deletions
+18 -4
View File
@@ -1,15 +1,29 @@
package datastore
import "xorm.io/xorm"
import (
"xorm.io/xorm"
"github.com/mayswind/ezbookkeeping/pkg/core"
)
// Database represents a database instance
type Database struct {
*xorm.EngineGroup
engineGroup *xorm.EngineGroup
}
// NewSession starts a new session with the specified context
func (db *Database) NewSession(c *core.Context) *xorm.Session {
return db.engineGroup.Context(NewXOrmContextAdapter(c))
}
// DoTransaction runs a new database transaction
func (db *Database) DoTransaction(fn func(sess *xorm.Session) error) (err error) {
sess := db.NewSession()
func (db *Database) DoTransaction(c *core.Context, fn func(sess *xorm.Session) error) (err error) {
sess := db.engineGroup.NewSession()
if c != nil {
sess.Context(NewXOrmContextAdapter(c))
}
defer sess.Close()
if err = sess.Begin(); err != nil {