code refactor

This commit is contained in:
MaysWind
2024-08-19 00:31:32 +08:00
parent 6fcb0a2b3c
commit e86d4e05ce
73 changed files with 1404 additions and 1344 deletions
+2 -2
View File
@@ -12,12 +12,12 @@ type Database struct {
}
// NewSession starts a new session with the specified context
func (db *Database) NewSession(c *core.Context) *xorm.Session {
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(c *core.Context, fn func(sess *xorm.Session) error) (err error) {
func (db *Database) DoTransaction(c core.Context, fn func(sess *xorm.Session) error) (err error) {
sess := db.engineGroup.NewSession()
if c != nil {
+2 -2
View File
@@ -28,12 +28,12 @@ func (s *DataStore) Choose(key int64) *Database {
}
// Query returns a new database session in a specific database by sharding key
func (s *DataStore) Query(c *core.Context, key int64) *xorm.Session {
func (s *DataStore) Query(c core.Context, key int64) *xorm.Session {
return s.Choose(key).NewSession(c)
}
// DoTransaction runs a new database transaction in a specific database by sharding key
func (s *DataStore) DoTransaction(key int64, c *core.Context, fn func(sess *xorm.Session) error) (err error) {
func (s *DataStore) DoTransaction(key int64, c core.Context, fn func(sess *xorm.Session) error) (err error) {
return s.Choose(key).DoTransaction(c, fn)
}
+2 -2
View File
@@ -39,10 +39,10 @@ func (c *XOrmContextAdapter) Value(key any) any {
return nil
}
func NewXOrmContextAdapter(c *core.Context) *XOrmContextAdapter {
func NewXOrmContextAdapter(c core.Context) *XOrmContextAdapter {
if c != nil {
return &XOrmContextAdapter{
requestId: c.GetRequestId(),
requestId: c.GetContextId(),
}
}