Documentation ¶
Index ¶
- func Count(ctx context.Context, db *gorm.DB, table interface{}, query interface{}, ...) (int64, error)
- func Create(ctx context.Context, db *gorm.DB, table interface{}) error
- func Delete(ctx context.Context, db *gorm.DB, table interface{}, query interface{}, ...) error
- func DeleteByID(ctx context.Context, db *gorm.DB, table interface{}, id interface{}) error
- func Get(ctx context.Context, db *gorm.DB, table interface{}, query interface{}, ...) error
- func GetByID(ctx context.Context, db *gorm.DB, table interface{}, id interface{}) error
- func GetTableName(object interface{}) string
- func Init(dns string, opts ...Option) (*gorm.DB, error)
- func List(ctx context.Context, db *gorm.DB, tables interface{}, page *query.Page, ...) error
- func TableName(table interface{}) string
- func Update(ctx context.Context, db *gorm.DB, table interface{}, column string, ...) error
- func Updates(ctx context.Context, db *gorm.DB, table interface{}, update KV, ...) error
- type KV
- type Model
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Count ¶ added in v1.3.0
func Count(ctx context.Context, db *gorm.DB, table interface{}, query interface{}, args ...interface{}) (int64, error)
Count number of records the param of 'table' must be pointer, eg: &StructName
func Create ¶ added in v1.3.0
Create a new record the param of 'table' must be pointer, eg: &StructName
func Delete ¶ added in v1.3.0
func Delete(ctx context.Context, db *gorm.DB, table interface{}, query interface{}, args ...interface{}) error
Delete record the param of 'table' must be pointer, eg: &StructName
func DeleteByID ¶ added in v1.3.0
DeleteByID delete record by id the param of 'table' must be pointer, eg: &StructName
func Get ¶ added in v1.3.0
func Get(ctx context.Context, db *gorm.DB, table interface{}, query interface{}, args ...interface{}) error
Get one record the param of 'table' must be pointer, eg: &StructName
func List ¶ added in v1.3.0
func List(ctx context.Context, db *gorm.DB, tables interface{}, page *query.Page, query interface{}, args ...interface{}) error
List multiple records, starting from page 0 the param of 'tables' must be slice, eg: []StructName
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:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-"` }
Model 表内嵌字段,嵌入到其他表结构体时添加 `gorm:"embedded"`
type Option ¶
type Option func(*options)
Option set the mysql options.
func WithConnMaxLifetime ¶
WithConnMaxLifetime set conn max lifetime
func WithEnableForeignKey ¶ added in v1.3.0
func WithEnableForeignKey() Option
WithEnableForeignKey use foreign keys
func WithSlowThreshold ¶ added in v1.3.0
WithSlowThreshold Set sql values greater than the threshold