mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 15:37:33 +08:00
add request id to sql query log
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user