Documentation
¶
Index ¶
- Constants
- Variables
- func CDN(host, path string, replaces ...bool) string
- func CDNRelativePath(cdnPath string) string
- func Dec(db *gorm.DB, column string, values ...any) error
- func ErrDryRunModeUnsupported(err error) bool
- func ErrDuplicatedKey(err error) bool
- func ErrEmptySlice(err error) bool
- func ErrForeignKeyViolated(err error) bool
- func ErrInvalidDB(err error) bool
- func ErrInvalidData(err error) bool
- func ErrInvalidField(err error) bool
- func ErrInvalidTransaction(err error) bool
- func ErrInvalidValue(err error) bool
- func ErrInvalidValueOfLength(err error) bool
- func ErrMissingWhereClause(err error) bool
- func ErrModelAccessibleFieldsRequired(err error) bool
- func ErrModelValueRequired(err error) bool
- func ErrNotImplemented(err error) bool
- func ErrPreloadNotAllowed(err error) bool
- func ErrPrimaryKeyRequired(err error) bool
- func ErrRecordNotFound(err error) bool
- func ErrRegistered(err error) bool
- func ErrSubQueryRequired(err error) bool
- func ErrUnsupportedDriver(err error) bool
- func ErrUnsupportedRelation(err error) bool
- func Inc(db *gorm.DB, column string, values ...any) error
- func MigrateViews(db *gorm.DB, views ...IView) error
- func ScopesCallbackWhereQueryArgs(fns ...func(queryArgs *QueryArgs)) func(db *gorm.DB) *gorm.DB
- func ScopesPage(page, size int) func(db *gorm.DB) *gorm.DB
- func ScopesWhereQueryArgs(queryArgs *QueryArgs) func(db *gorm.DB) *gorm.DB
- type Criteria
- type DBCallback
- type DBMap
- func (g *DBMap) DB() *gorm.DB
- func (g *DBMap) Exist(name string) bool
- func (g *DBMap) Get(name string) (*gorm.DB, error)
- func (g *DBMap) GetDBNames() []string
- func (g *DBMap) MustGet(name string) *gorm.DB
- func (g *DBMap) OnRegisterCallback(callback DBCallback) *DBMap
- func (g *DBMap) Register(name string, db *gorm.DB) error
- func (g *DBMap) RegisterByConfig(config IConfig, names ...string) error
- func (g *DBMap) RegisterByNameDBConfig(config INameDBConfig) error
- func (g *DBMap) RegisterByPtrConfig(ptr any) error
- type ErrMapDB
- type GORMConfig
- type IConfig
- type IDModel
- type IModel
- type INameDBConfig
- type IQueryArgs
- type IView
- type NamingStrategy
- type PageResponse
- type QueryArgs
- func (q *QueryArgs) Between(column string, s any, e any) *QueryArgs
- func (q *QueryArgs) Eq(column string, value any) *QueryArgs
- func (q *QueryArgs) Ge(column string, value any) *QueryArgs
- func (q *QueryArgs) Gt(column string, value any) *QueryArgs
- func (q *QueryArgs) In(column string, value []any) *QueryArgs
- func (q *QueryArgs) IsNotNull(column string) *QueryArgs
- func (q *QueryArgs) IsNull(column string) *QueryArgs
- func (q *QueryArgs) Le(column string, value any) *QueryArgs
- func (q *QueryArgs) Like(column string, value any) *QueryArgs
- func (q *QueryArgs) Lt(column string, value any) *QueryArgs
- func (q *QueryArgs) Ne(column string, value any) *QueryArgs
- func (q *QueryArgs) NotBetween(column string, s any, e any) *QueryArgs
- func (q *QueryArgs) NotIn(column string, value []any) *QueryArgs
- func (q *QueryArgs) NotLike(column string, value any) *QueryArgs
- func (q *QueryArgs) OrWhere(column string, operator string, value []any) *QueryArgs
- func (q *QueryArgs) Where(column string, operator string, value []any, connector string) *QueryArgs
- func (q *QueryArgs) WhereQueryArgs() (string, []any)
- type SoftModel
- type TimeModel
Constants ¶
View Source
const ( ErrDBMapAddExist int = iota + 1 ErrDBMapGetNotFind ErrDBMapStruct )
View Source
const ( ConnectorAnd = "AND" ConnectorOr = "OR" )
View Source
const ( OperatorIn = "IN" OperatorNot = "NOT" OperatorLike = "LIKE" OperatorEq = "=" OperatorNe = "<>" OperatorGt = ">" OperatorGe = ">=" OperatorLt = "<" OperatorLe = "<=" OperatorIsNull = "IS NULL" OperatorIsNotNull = "IS NOT NULL" OperatorBetween = "BETWEEN" OperatorNotBetween = OperatorNot + " " + OperatorBetween OperatorNotIn = OperatorNot + " " + OperatorIn OperatorNotLike = OperatorNot + " " + OperatorLike )
View Source
const ( OrderByDesc = "DESC" OrderByAsc = "ASC" )
View Source
const ( SUM = "SUM" AVG = "AVG" MAX = "MAX" MIN = "MIN" COUNT = "COUNT" )
View Source
const (
DBMapENVMainDB = "main_db"
)
Variables ¶
View Source
var ( DefaultPageQueryPage = "page" DefaultPageQuerySize = "size" DefaultPageQueryMaxSize = 100 DefaultPageQueryDefaultSize = 10 )
View Source
var ( DefaultLogger = logger.Default DefaultGORMConfig = &gorm.Config{ QueryFields: true, PrepareStmt: true, NamingStrategy: schema.NamingStrategy{ SingularTable: true, }, Logger: DefaultLogger, } )
Functions ¶
func ErrDuplicatedKey ¶
func ErrEmptySlice ¶
func ErrForeignKeyViolated ¶
func ErrInvalidDB ¶
func ErrInvalidData ¶
func ErrInvalidField ¶
func ErrInvalidTransaction ¶
func ErrInvalidValue ¶
func ErrInvalidValueOfLength ¶
func ErrMissingWhereClause ¶
func ErrModelValueRequired ¶
func ErrNotImplemented ¶
func ErrPreloadNotAllowed ¶
func ErrPrimaryKeyRequired ¶
func ErrRecordNotFound ¶
func ErrRegistered ¶
func ErrSubQueryRequired ¶
func ErrUnsupportedDriver ¶
func ErrUnsupportedRelation ¶
func ScopesCallbackWhereQueryArgs ¶ added in v0.0.2
func ScopesPage ¶
ScopesPage db.Scopes(Paginate(r)).Find(&users)
Types ¶
type DBCallback ¶
func DBCallbackOnErrorOnNotFound ¶
func DBCallbackOnErrorOnNotFound() DBCallback
DBCallbackOnErrorOnNotFound https://github.com/go-gorm/gorm/issues/3789
func DBCallbackOnPool ¶
func DBCallbackOnPool(maxIdleConns, maxOpenConns int, d time.Duration) DBCallback
DBCallbackOnPool https://gorm.io/zh_CN/docs/generic_interface.html#%E8%BF%9E%E6%8E%A5%E6%B1%A0
type DBMap ¶
type DBMap struct {
// contains filtered or unexported fields
}
func DefaultDBMap ¶
func DefaultDBMap() *DBMap
func (*DBMap) GetDBNames ¶ added in v0.0.3
GetDBNames 获取所有注册的数据别名
func (*DBMap) OnRegisterCallback ¶
func (g *DBMap) OnRegisterCallback(callback DBCallback) *DBMap
OnRegisterCallback 注入在注册的回掉函数
func (*DBMap) RegisterByConfig ¶ added in v0.0.3
RegisterByConfig 根据config进行注册config exp mysql.Config
func (*DBMap) RegisterByNameDBConfig ¶ added in v0.0.3
func (g *DBMap) RegisterByNameDBConfig(config INameDBConfig) error
RegisterByNameDBConfig 批量注册db
func (*DBMap) RegisterByPtrConfig ¶ added in v0.0.3
RegisterByPtrConfig exp:
type DBMapConfig struct { Test *mysql.Config `gorm:"test"` }
type ErrMapDB ¶
func NewErrMapDB ¶
type GORMConfig ¶
type GORMConfig struct { // GORM perform single create, update, delete operations in transactions by default to ensure database data integrity // You can disable it by setting `SkipDefaultTransaction` to true SkipDefaultTransaction bool // FullSaveAssociations full save associations FullSaveAssociations bool // DryRun generate sql without execute DryRun bool // PrepareStmt executes the given query in cached statement PrepareStmt bool // DisableAutomaticPing DisableAutomaticPing bool // DisableForeignKeyConstraintWhenMigrating DisableForeignKeyConstraintWhenMigrating bool // IgnoreRelationshipsWhenMigrating IgnoreRelationshipsWhenMigrating bool // DisableNestedTransaction disable nested transaction DisableNestedTransaction bool // AllowGlobalUpdate allow global update AllowGlobalUpdate bool // QueryFields executes the SQL query with all fields of the table QueryFields bool // CreateBatchSize default create batch size CreateBatchSize int // TranslateError enabling error translation TranslateError bool //tables, columns naming strategy NamingStrategy *NamingStrategy }
func (*GORMConfig) GORMConfig ¶
func (config *GORMConfig) GORMConfig() *gorm.Config
type INameDBConfig ¶ added in v0.0.3
type IQueryArgs ¶
type NamingStrategy ¶
type PageResponse ¶
type PageResponse[T any] struct { //当前分页数 CurrentPage int `json:"current_page" xml:"CurrentPage"` //当前拉去多少条 CurrentSize int `json:"current_size" xml:"CurrentSize"` //总数 Total int64 `json:"total" xml:"Total"` //列表 Items []T `json:"items" xml:"Items"` }
func Paginate ¶
Paginate https://gorm.io/zh_CN/docs/scopes.html#%E5%88%86%E9%A1%B5 db := db.Model(Model{}) paginate, _ := Paginate[*Model](db, context.Request)
type QueryArgs ¶
type QueryArgs struct {
// contains filtered or unexported fields
}
func NewQueryArgs ¶ added in v0.0.2
func NewQueryArgs() *QueryArgs
func (*QueryArgs) NotBetween ¶
NotBetween NOT BETWEEN 值1 AND 值2
func (*QueryArgs) WhereQueryArgs ¶
WhereQueryArgs where 条件筛选 args = NewSQLArgs() db.Scopes(ScopesWhereQueryArgs(args)).Find(&users)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.