diff --git a/db/alias.go b/db/alias.go index 83d4b1791809df79b5b2f9bd483d3f40fdd6de99..6156fffda28854fe678161ac438eafd54ce00454 100644 --- a/db/alias.go +++ b/db/alias.go @@ -16,130 +16,137 @@ package db import ( - "gitee.com/go-libs/db-xorm/db/src" - "gitee.com/go-libs/db-xorm/db/types" + "gitee.com/go-libs/db-xorm/db/commands/model" + "gitee.com/go-libs/db-xorm/db/commands/service" + "gitee.com/go-libs/db-xorm/db/src" + "gitee.com/go-libs/db-xorm/db/types" ) // Alias for xorm. type ( - Session = src.Session + Session = src.Session ) // Alias for src. var ( - // Config - // is an alias for src.Config. You can open a master or slave connect - // session like follows. - // - // Master: - // session, err := db.Config.GetMaster(ctx) - // - // Slave: - // session, err := db.Config.GetSlave(ctx) - Config = src.Config - - // Transaction - // is an alias for src.Transaction. - Transaction = src.Transaction - - // TransactionWithSession - // is an alias for src.Transaction. - TransactionWithSession = src.TransactionWithSession + // Config + // is an alias for src.Config. You can open a master or slave connect + // session like follows. + // + // Master: + // session, err := db.Config.GetMaster(ctx) + // + // Slave: + // session, err := db.Config.GetSlave(ctx) + Config = src.Config + + // Transaction + // is an alias for src.Transaction. + Transaction = src.Transaction + + // TransactionWithSession + // is an alias for src.Transaction. + TransactionWithSession = src.TransactionWithSession ) type ( - // Database - // is an alias for database connection configuration. - // - // File: configure in config/db.yaml like follows: - // - // database: - // my: - // driver: mysql - // dsn: - // - user:pass@tcp(127.0.0.1)/name?charset=utf8 - // - // Code: in your code like follows: - // - // db.Config.Add("my", &db.Database{ - // Driver: "mysql", - // Dsn: []string{ - // "user:pass@tcp(127.0.0.1)/name?charset=utf8", - // }, - // }) - // - // Usage: - // - // db.Config.GetMaster(ctx, "my") - // db.Config.GetSlave(ctx, "my") - Database = src.Database - - // Service - // is an alias for src.Service. It's a top level service. You can - // import it as an anonymous. - // - // Definition: - // - // type YourService struct { - // db.Service - // } - // - // func NewYourService(sessions ... *db.Session) *YourService { - // service := &YourService{} - // service.With(sessions...) - // return service - // } - // - // func (o *YourService) List(ctx context.Context)(list []models.Example, err error){ - // var session *db.Session - // - // if session, err = o.Slave(ctx); err != nil { - // return - // } - // - // err = session.Find(&list) - // return - // } - // - // Usage: - // - // svc := services.NewYourService() - // list, err := svc.List(ctx) - Service = src.Service - - // TransactionHandler - // is an alias hook for src.TransactionHandler. Do not run handler - // in goroutine for each transaction. - TransactionHandler = src.TransactionHandler + // Database + // is an alias for database connection configuration. + // + // File: configure in config/db.yaml like follows: + // + // database: + // my: + // driver: mysql + // dsn: + // - user:pass@tcp(127.0.0.1)/name?charset=utf8 + // + // Code: in your code like follows: + // + // db.Config.Add("my", &db.Database{ + // Driver: "mysql", + // Dsn: []string{ + // "user:pass@tcp(127.0.0.1)/name?charset=utf8", + // }, + // }) + // + // Usage: + // + // db.Config.GetMaster(ctx, "my") + // db.Config.GetSlave(ctx, "my") + Database = src.Database + + // Service + // is an alias for src.Service. It's a top level service. You can + // import it as an anonymous. + // + // Definition: + // + // type YourService struct { + // db.Service + // } + // + // func NewYourService(sessions ... *db.Session) *YourService { + // service := &YourService{} + // service.With(sessions...) + // return service + // } + // + // func (o *YourService) List(ctx context.Context)(list []models.Example, err error){ + // var session *db.Session + // + // if session, err = o.Slave(ctx); err != nil { + // return + // } + // + // err = session.Find(&list) + // return + // } + // + // Usage: + // + // svc := services.NewYourService() + // list, err := svc.List(ctx) + Service = src.Service + + // TransactionHandler + // is an alias hook for src.TransactionHandler. Do not run handler + // in goroutine for each transaction. + TransactionHandler = src.TransactionHandler ) // Definitions. var ( - // NewDate - // is an alias for types.NewDate. - NewDate = types.NewDate + // NewDate + // is an alias for types.NewDate. + NewDate = types.NewDate - // NewDatetime - // is an alias for types.NewDatetime. - NewDatetime = types.NewDatetime + // NewDatetime + // is an alias for types.NewDatetime. + NewDatetime = types.NewDatetime ) // Now // is an alias for src.Now. It's returned a Datetime type of // current time. func Now() types.Datetime { - return NewDatetime() + return NewDatetime() } type ( - // Date - // is an alias for types.Date. It's a wrapper of time.Time. - Date = types.Date + // Date + // is an alias for types.Date. It's a wrapper of time.Time. + Date = types.Date - // Datetime - // is an alias for types.Datetime. It's a wrapper of time.Time. - Datetime = types.Datetime + // Datetime + // is an alias for types.Datetime. It's a wrapper of time.Time. + Datetime = types.Datetime +) + +var ( + NewGenModelCommand = model.New + NewGenServiceCommand = service.New )