Documentation ¶
Overview ¶
Package ggorm is a library wrapped on top of gorm.io/gorm, with added features such as link tracing, paging queries, etc.
Index ¶
- Constants
- func CloseDB(db *gorm.DB) error
- func CloseSQLDB(db *gorm.DB)
- func GetTableName(object interface{}) string
- func InitMysql(dsn string, opts ...Option) (*gorm.DB, error)
- func InitPostgresql(dsn string, opts ...Option) (*gorm.DB, error)
- func InitSqlite(dbFile string, opts ...Option) (*gorm.DB, error)
- func InitTidb(dsn string, opts ...Option) (*gorm.DB, error)
- func NewCustomGormLogger(o *options) logger.Interface
- type KV
- type Model
- type Model2
- type Option
- func WithConnMaxLifetime(t time.Duration) Option
- func WithEnableForeignKey() Option
- func WithEnableTrace() Option
- func WithGormPlugin(plugins ...gorm.Plugin) Option
- func WithLogRequestIDKey(key string) Option
- func WithLogging(l *zap.Logger, level ...logger.LogLevel) Option
- func WithMaxIdleConns(size int) Option
- func WithMaxOpenConns(size int) Option
- func WithRWSeparation(slavesDsn []string, mastersDsn ...string) Option
- func WithSlowThreshold(d time.Duration) Option
Constants ¶
const ( // DBDriverMysql mysql driver DBDriverMysql = "mysql" // DBDriverPostgresql postgresql driver DBDriverPostgresql = "postgresql" // DBDriverTidb tidb driver DBDriverTidb = "tidb" // DBDriverSqlite sqlite driver DBDriverSqlite = "sqlite" )
Variables ¶
This section is empty.
Functions ¶
func InitPostgresql ¶
InitPostgresql init postgresql
func InitSqlite ¶
InitSqlite init sqlite
func NewCustomGormLogger ¶
NewCustomGormLogger custom gorm logger
Types ¶
type Model ¶
type Model struct { ID uint64 `gorm:"column:id;AUTO_INCREMENT;primary_key" json:"id"` CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"` }
Model embedded structs, add `gorm: "embedded"` when defining table structs
type Model2 ¶
type Model2 struct { ID uint64 `gorm:"column:id;AUTO_INCREMENT;primary_key" json:"id"` CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"` }
Model2 embedded structs, json tag named is snake case
type Option ¶
type Option func(*options)
Option set the mysql options.
func WithConnMaxLifetime ¶
WithConnMaxLifetime set conn max lifetime
func WithEnableForeignKey ¶
func WithEnableForeignKey() Option
WithEnableForeignKey use foreign keys
func WithGormPlugin ¶
WithGormPlugin setting gorm plugin
func WithLogRequestIDKey ¶
WithLogRequestIDKey log request id
func WithLogging ¶
WithLogging set log sql, If l=nil, the gorm log library will be used
func WithRWSeparation ¶
WithRWSeparation setting read-write separation
func WithSlowThreshold ¶
WithSlowThreshold Set sql values greater than the threshold