repository.go 398 B

123456789101112131415161718192021222324
  1. package repository
  2. import (
  3. "github.com/go-xorm/xorm"
  4. "github.com/hwholiday/gid/v2/configs"
  5. "github.com/hwholiday/gid/v2/library/database/mysql"
  6. )
  7. type Repository struct {
  8. c *configs.Config
  9. db *xorm.Engine
  10. }
  11. func NewRepository(c *configs.Config) (r *Repository) {
  12. r = &Repository{
  13. c: c,
  14. db: mysql.NewMysql(c.Mysql),
  15. }
  16. return r
  17. }
  18. func (r *Repository) Close() {
  19. _ = r.db.Close()
  20. }