Documentation ¶
Index ¶
- Constants
- Variables
- func GormOpen() (db *gorm.DB, err error)
- func HumanDate(date time.Time) int
- func ParsePaging(index, size, defaultSize int) (skip, take int)
- func ParseTimeRange(humanDate ...string) (s int, e int)
- func RegisterDialector(name string, dialector func(dsn string) gorm.Dialector)
- func Sort[K strs.Int | ~string](db *gorm.DB, keyCol, sortCol string, keys []K, reverse ...bool) *gorm.DB
- func SortExpr[K strs.Int | ~string](keys []K, reverses ...bool) clause.Expression
- func SortMap[K strs.Int | ~string, S strs.Int](db *gorm.DB, keyCol, sortCol string, sorts map[K]S) *gorm.DB
- func SortMapExpr[K strs.Int | ~string, S strs.Int](sorts map[K]S) clause.Expr
- func SortMapSimple[K strs.Int | ~string, S strs.Int](db *gorm.DB, sorts map[K]S) *gorm.DB
- func SortSimple[K strs.Int | ~string](db *gorm.DB, keys []K, reverse ...bool) *gorm.DB
- type Config
- type LoggerWriter
- type Scope
- type Table
- type Tabled
- type Transaction
Constants ¶
View Source
const ( MYSQL_DSN = "{user}:{password}@tcp({server}:{port})/{name}?{args}" //?charset={charset}&parseTime=True&loc=Local&timeout=10s PQ_DSN = "user={user} password={password} host={server} port={port} dbname={name} {args}" // sslmode=disable TimeZone=Asia/Shanghai SQLITE_DSN = "{path}?{args}" //?_pragma=busy_timeout(3000)&_pragma=journal_mode(WAL) )
Variables ¶
View Source
var ( DoNothing = Clauses(clause.OnConflict{DoNothing: true}) UpdateAll = Clauses(clause.OnConflict{UpdateAll: true}) Conflict = func(onConflict clause.OnConflict) Scope { return Clauses(onConflict) } DoUpdates = func(columns ...string) Scope { return Clauses(clause.OnConflict{DoUpdates: clause.AssignmentColumns(columns)}) } )
OnConflict
View Source
var DefaultConfig = &gorm.Config{ NamingStrategy: SingularTable, SkipDefaultTransaction: true, PrepareStmt: true, DisableForeignKeyConstraintWhenMigrating: true, }
View Source
var SingularTable = schema.NamingStrategy{SingularTable: true}
Functions ¶
func ParsePaging ¶
func ParseTimeRange ¶
func RegisterDialector ¶
func SortMapSimple ¶
满足排序字段为sort且为数值型, 单主键且为数值型
Types ¶
type Config ¶
type Config struct { Type string `json:"type,omitempty"` // 数据库类型 User string `json:"user,omitempty"` // 用户 Password string `json:"password,omitempty"` // 密码 Host string `json:"host,omitempty"` // 服务器 Port int `json:"port,omitempty"` // 端口 Name string `json:"name,omitempty"` // 数据库名 Path string `json:"path,omitempty"` // 文件路径 Args string `json:"args,omitempty"` // 扩展参数 Debug bool `json:"debug,omitempty"` // 调试模式 }
func DefineConfig ¶
type LoggerWriter ¶
type LoggerWriter bool
func (LoggerWriter) Printf ¶
func (w LoggerWriter) Printf(format string, v ...any)
type Scope ¶
func CreatedDateRange ¶
type Table ¶
func (Table) GetCreatedAt ¶
type Transaction ¶
Click to show internal directories.
Click to hide internal directories.