mysql

package
v0.0.0-...-81db2af Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WriteOrRead = Action(1)
	ReadOnly    = Action(2)
)
View Source
const (
	EqualOperator           = FilterOperator("=")
	LikeOperator            = FilterOperator("like")
	InOperator              = FilterOperator("in")
	LessThanOperator        = FilterOperator("<")
	GreaterThanOperator     = FilterOperator(">")
	NotInOperator           = FilterOperator("not in")
	LessThanOrEqualOperator = FilterOperator("<=")

	// zero value
	ZeroLimit   = Limit(-1)
	ZeroOrderBy = OrderBy("")

	IDFieldName = "id"
)
View Source
const (
	// MaxOpenConn --
	MaxOpenConn = 100
	// MaxIdleConn --
	MaxIdleConn = 10
)

Variables

This section is empty.

Functions

func GenPreloadItemArgs

func GenPreloadItemArgs(args ...interface{}) []interface{}

func GenPreloadItemHandlerFunc

func GenPreloadItemHandlerFunc(handler func(db *gorm.DB) *gorm.DB) []interface{}

func NewDefaultMysqlGormConn

func NewDefaultMysqlGormConn(conn *Connection, dbUrl string, debug bool) *gorm.DB

NewDefaultMysqlGormConn --

Types

type Action

type Action int

type AtMysql

type AtMysql struct {
	*sql.DB
}

AtMysql --

func CreateMysqlConnection

func CreateMysqlConnection(conn *Connection) *AtMysql

CreateMysqlConnection --

func NewConnection

func NewConnection(conn *Connection) (*AtMysql, error)

NewConnection -- open connection to db

func (*AtMysql) Close

func (c *AtMysql) Close()

Close -- close connection

func (*AtMysql) GetDB

func (c *AtMysql) GetDB() *sql.DB

GetDB -- get db

type Connection

type Connection struct {
	Host         string
	Port         int
	Protocol     string
	User         string
	Password     string
	DatabaseName string
	Charset      string
	ParseTime    bool
	Location     string
	Others       string
	EnableLog    bool
	MaxOpenConn  int
	MaxIdleConn  int
	ServiceName  string
}

Connection -- mysql connection

func DefaultMysqlConnectionFromConfig

func DefaultMysqlConnectionFromConfig() *Connection

DefaultMysqlConnectionFromConfig -- load connection settings in config with default key

type FilterItem

type FilterItem struct {
	FieldName string
	Operator  FilterOperator
	Value     interface{}

	// these fields are used for this statement: db.Where(a.RawQuery, a.Args...)
	RawQuery string
	Args     []interface{}
	// contains filtered or unexported fields
}

type FilterOperator

type FilterOperator string

type FilterOrderBy

type FilterOrderBy struct{}

type Filters

type Filters []FilterItem

type IBaseRepository

type IBaseRepository interface {
	GetDB(actions ...Action) *gorm.DB
	FindOneHandler(ctx context.Context, result interface{}, args ...interface{}) error
	FindByIDHandler(ctx context.Context, ID int, result interface{}, args ...interface{}) error
	FindsHandler(ctx context.Context, result interface{}, args ...interface{}) error
	// contains filtered or unexported methods
}

func NewBaseRepository

func NewBaseRepository(masterDB *gorm.DB, replicaDB ...*gorm.DB) IBaseRepository

type Limit

type Limit int

func NewLimit

func NewLimit(i interface{}) Limit

func (Limit) IsZero

func (a Limit) IsZero() bool

func (Limit) SetCondition

func (a Limit) SetCondition(db *gorm.DB) *gorm.DB

type OrderBy

type OrderBy string

func (OrderBy) IsZero

func (a OrderBy) IsZero() bool

func (OrderBy) SetCondition

func (a OrderBy) SetCondition(db *gorm.DB) *gorm.DB

type PreloadArgsFunc

type PreloadArgsFunc func(db *gorm.DB) *gorm.DB

Example

func(db *gorm.DB) *gorm.DB {
	  return db.Where("info_type = 0") // schema_markup
}

type PreloadItem

type PreloadItem struct {
	Column string
	Args   []interface{}
	// contains filtered or unexported fields
}

type Preloads

type Preloads []PreloadItem

Jump to

Keyboard shortcuts

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