orm

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDBNotFound = errors.New("the db singletons not found or not initialization")
)

Functions

func AutoInitGormWithConfig

func AutoInitGormWithConfig()
db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{
	NamingStrategy: schema.NamingStrategy{
	  TablePrefix: "t_",   // table name prefix, table for `User` would be `t_users`
	  SingularTable: true, // use singular table name, table for `User` would be `user` with this option enabled
	  NoLowerCase: true, // skip the snake_casing of names
	  NameReplacer: strings.NewReplacer("CID", "Cid"), // use name replacer to change struct/field name before convert it to db name
	},
  })

func GetGormSingleton

func GetGormSingleton(name string) (gdb *gorm.DB, err error)

GetGormSingleton 获取GetGormSingleton单例

func GetGormSingletonByModel

func GetGormSingletonByModel(gormmodel GormModel) (gdb *gorm.DB, err error)

func InitGorm

func InitGorm(dbname string, cfg GormConfig) error

Types

type GormConfig

type GormConfig struct {
	MysqlConfig    *mysql.Config
	GormConfig     *gorm.Config
	ConnPoolConfig GormConnPoolConfig
}

type GormConnPoolConfig

type GormConnPoolConfig struct {
	MaxIdleConns int
	MaxOpenConns int
}

type GormLog

type GormLog struct {
	Logger *fileLogger.FileLogger
	Config GormLogConfig
	// contains filtered or unexported fields
}
type Interface interface {
    LogMode(LogLevel) Interface
    Info(context.Context, string, ...interface{})
    Warn(context.Context, string, ...interface{})
    Error(context.Context, string, ...interface{})
    Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)
}

func NewGormLogger

func NewGormLogger(config GormLogConfig) *GormLog

func (*GormLog) Error

func (gl *GormLog) Error(ctx context.Context, format string, args ...interface{})

func (*GormLog) Info

func (gl *GormLog) Info(ctx context.Context, format string, args ...interface{})

func (*GormLog) LogMode

func (gl *GormLog) LogMode(lv glog.LogLevel) glog.Interface

func (*GormLog) Prefix

func (gl *GormLog) Prefix() string

func (*GormLog) Trace

func (gl *GormLog) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*GormLog) Warn

func (gl *GormLog) Warn(ctx context.Context, format string, args ...interface{})

func (*GormLog) WithPrefix

func (gl *GormLog) WithPrefix(prefix string) glog.Interface

type GormLogConfig

type GormLogConfig struct {
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
	Level                     glog.LogLevel
	LogName                   string
	LogPath                   string
	Prefix                    string
}

type GormModel

type GormModel interface {
	DbName() string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL