gormdb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClient = errors.New("mysql client is not initialized yet")
)

Functions

func Cli added in v0.1.0

func Cli(ctx context.Context) *gorm.DB

Cli is a shortcut

func KeywordGenerator

func KeywordGenerator(columnList []string, keyword string) func(db *gorm.DB) *gorm.DB

Types

type BasicQuery

type BasicQuery struct {
	IDList  []int64  `json:"IdList"`  // id数组
	Fields  []string `json:"Fields"`  // 指定返回字段
	Keyword string   `json:"Keyword"` // 关键词(全局模糊搜索)
	Order   string   `json:"Order"`   // 排序,支持desc和asc
	Limit   int      `json:"Limit"`   // 分页条数
	Offset  int      `json:"Offset"`  // 分页偏移量
	Query   string   `json:"Query"`   // 自定义查询语句;使用RSQL语法
}

type CRUDImpl

type CRUDImpl struct {
	Conn *gorm.DB
}

func (*CRUDImpl) Create

func (c *CRUDImpl) Create(model interface{}) (err error)

Create model must be a pointer

func (*CRUDImpl) Delete

func (c *CRUDImpl) Delete(m interface{}, hardDelete bool) (err error)

Delete model must be a pointer

func (*CRUDImpl) FindByCon

func (c *CRUDImpl) FindByCon(con, model interface{}, args ...interface{}) (err error)

FindByCon conditions could be pointer of a model struct, map or string model must be a pointer

func (*CRUDImpl) GetByID

func (c *CRUDImpl) GetByID(model interface{}, id int64) (err error)

GetByID model must be a pointer

func (*CRUDImpl) GetList

func (c *CRUDImpl) GetList(q BasicQuery, model, list interface{}) (total int64, err error)

GetList model and list must be a pointer

func (*CRUDImpl) GetOneByCon

func (c *CRUDImpl) GetOneByCon(con, model interface{}, args ...interface{}) (err error)

GetOneByCon conditions could be pointer of a model struct, map or string model must be a pointer

func (*CRUDImpl) UpdateWithMap

func (c *CRUDImpl) UpdateWithMap(model interface{}, u map[string]interface{}) (err error)

UpdateWithMap model must be a pointer

type CreateCrud

type CreateCrud interface {
	Create(model interface{}) error
}

type DB

type DB struct {
	// contains filtered or unexported fields
}

func GetDB

func GetDB() *DB

func (*DB) Close

func (d *DB) Close() (err error)

func (*DB) Master

func (d *DB) Master(ctx context.Context) *gorm.DB

Master check *gorm.DB if is nil

func (*DB) Migration

func (d *DB) Migration(dst ...interface{}) error

type DBConfig

type DBConfig struct {
	WriteDBHost     string   `yaml:"write_db_host" env:"MySQLWriteHost" env-description:"mysql master host"`
	WriteDBPort     uint16   `yaml:"write_db_port" env:"MySQLWritePort" env-description:"mysql master port"`
	WriteDBUser     string   `yaml:"write_db_user" env:"MySQLWriteUser" env-description:"mysql master user"`
	WriteDBPassword string   `yaml:"write_db_password" env:"MySQLWritePassword" env-description:"mysql master password"`
	WriteDB         string   `yaml:"write_db" env:"MySQLWriteDB" env-description:"mysql master database"`
	ReadDBHostList  []string `yaml:"read_db_host_list" env:"MySQLReadHostList" env-description:"mysql slave host list"`
	ReadDBPort      uint16   `yaml:"read_db_port" env:"MySQLReadPort" env-description:"mysql slave port"`
	ReadDBUser      string   `yaml:"read_db_user" env:"MySQLReadUser" env-description:"mysql slave user"`
	ReadDBPassword  string   `yaml:"read_db_password" env:"MySQLReadPassword" env-description:"mysql slave password"`
	ReadDB          string   `yaml:"read_db" env:"MySQLReadDB" env-description:"mysql slave database"`
	Prefix          string   `yaml:"table_prefix"`
	MaxIdleConns    int      `yaml:"max_idle_conns"`
	MaxOpenConns    int      `yaml:"max_open_conns"`
	Logging         bool     `yaml:"logging"`
	LogLevel        string   `yaml:"log_level" env:"MySQLLogLevel" env-description:"log level of mysql log: silent/info/warn/error"`
	RawColumn       bool     `yaml:"-"`
}

func (DBConfig) BuildMySQLClient

func (c DBConfig) BuildMySQLClient(ctx context.Context) (*DB, error)

type DBLog

type DBLog struct {
	logg.Config
}

func (DBLog) Error

func (d DBLog) Error(ctx context.Context, msg string, data ...interface{})

func (DBLog) Info

func (d DBLog) Info(ctx context.Context, msg string, data ...interface{})

func (*DBLog) LogMode

func (d *DBLog) LogMode(level logg.LogLevel) logg.Interface

func (DBLog) Trace

func (d DBLog) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (DBLog) Warn

func (d DBLog) Warn(ctx context.Context, msg string, data ...interface{})

type DeleteCrud

type DeleteCrud interface {
	Delete(model interface{}, hardDelete bool) error
}

type FindByConCrud added in v0.1.0

type FindByConCrud interface {
	FindByCon(con, model interface{}, args ...interface{}) error
}

type GetByConCrud added in v0.1.0

type GetByConCrud interface {
	GetOneByCon(con, model interface{}, args ...interface{}) error
}

type GetByIDCrud added in v0.1.0

type GetByIDCrud interface {
	GetByID(model interface{}, id int64) error
}

type GetListCrud

type GetListCrud interface {
	GetList(q BasicQuery, model, list interface{}) (total int64, err error)
}

type MyNamingStrategy

type MyNamingStrategy struct {
	// contains filtered or unexported fields
}

MyNamingStrategy 只改了ColumnName,直接返回结构体的字段名(用于大驼峰标准)

func (MyNamingStrategy) CheckerName

func (mns MyNamingStrategy) CheckerName(table, column string) string

CheckerName generate checker name

func (MyNamingStrategy) ColumnName

func (mns MyNamingStrategy) ColumnName(table, column string) string

ColumnName convert string to column name

func (MyNamingStrategy) IndexName

func (mns MyNamingStrategy) IndexName(table, column string) string

IndexName generate index name

func (MyNamingStrategy) JoinTableName

func (mns MyNamingStrategy) JoinTableName(str string) string

JoinTableName convert string to join table name

func (MyNamingStrategy) RelationshipFKName

func (mns MyNamingStrategy) RelationshipFKName(rel schema.Relationship) string

RelationshipFKName generate fk name for relation

func (MyNamingStrategy) SchemaName

func (mns MyNamingStrategy) SchemaName(table string) string

func (MyNamingStrategy) TableName

func (mns MyNamingStrategy) TableName(str string) string

type UpdateCrud

type UpdateCrud interface {
	UpdateWithMap(model interface{}, u map[string]interface{}) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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