Documentation ¶
Index ¶
- Variables
- func Delete(db *gorm.DB, model any, opts ...QueryOption) error
- func DeleteWithContext(ctx context.Context, db *gorm.DB, model any, opts ...QueryOption) error
- func Find[T any](db *gorm.DB, out *[]*T, p Pager, opts ...QueryOption) (int64, error)
- func FindWithContext[T any](ctx context.Context, db *gorm.DB, out *[]*T, p Pager, opts ...QueryOption) (int64, error)
- func First(db *gorm.DB, out any, opts ...QueryOption) error
- func FirstWithContext(ctx context.Context, db *gorm.DB, out any, opts ...QueryOption) error
- func GenerateRandomString(length int) string
- func IsDuplicatedKey(err error) bool
- func IsErrRecordNotFound(err error) bool
- func JsonUnmarshal(input, obj any) error
- func New(debug bool, dialector gorm.Dialector, cfg Config, w logger.Writer) (*gorm.DB, error)
- func Update[T any](db *gorm.DB, model *T, changeFn func(*T), opts ...QueryOption) error
- func UpdateWithContext[T any](ctx context.Context, db *gorm.DB, model *T, changeFn func(*T), ...) error
- type Config
- type DeletedAt
- type DeletedModel
- type Engine
- func (e Engine) DeleteOne(model Tabler, opts ...Option) error
- func (e Engine) Find(model Tabler, bean any, opts ...Option) (total int64, err error)
- func (e Engine) FirstOrCreate(b any) (bool, error)
- func (e Engine) InsertOne(model Tabler) error
- func (e Engine) NextSeq(model Tabler) (nextID int, err error)
- func (e Engine) UpdateOne(model Tabler, id int, data map[string]any) error
- type Logger
- type Model
- type ModelWithStrID
- type Option
- type Pager
- type QueryOption
- type Scaner
- type Tabler
- type Time
- type Type
- func (t Type[T]) Create(model *T) error
- func (t Type[T]) Delete(model *T, opts ...QueryOption) error
- func (t Type[T]) Find(out *[]*T, p Pager, opts ...QueryOption) (int64, error)
- func (t *Type[T]) First(out *T, opts ...QueryOption) error
- func (t Type[T]) Update(model *T, changeFn func(*T), opts ...QueryOption) error
- type Universal
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRevordNotFound = gorm.ErrRecordNotFound ErrDuplicatedKey = gorm.ErrDuplicatedKey )
Functions ¶
func DeleteWithContext ¶ added in v1.0.2
func FindWithContext ¶ added in v1.0.2
func FirstWithContext ¶ added in v1.0.2
func GenerateRandomString ¶
func IsDuplicatedKey ¶
func IsErrRecordNotFound ¶
func Update ¶
func Update[T any](db *gorm.DB, model *T, changeFn func(*T), opts ...QueryOption) error
func UpdateWithContext ¶ added in v1.0.2
Types ¶
type DeletedModel ¶
DeletedModel 删除模型
func (*DeletedModel) BeforeCreate ¶
func (d *DeletedModel) BeforeCreate(*gorm.DB) error
func (*DeletedModel) BeforeUpdate ¶
func (d *DeletedModel) BeforeUpdate(*gorm.DB) error
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (Engine) FirstOrCreate ¶
FirstOrCreate true:创建;false:查询
type Model ¶
type Model struct { ID int `gorm:"primaryKey;" json:"id"` CreatedAt Time `gorm:"notNull;default:CURRENT_TIMESTAMP;index;comment:创建时间" json:"created_at"` UpdatedAt Time `gorm:"notNull;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` }
Model int id 模型 sqlite 不支持 default:now(),支持 CURRENT_TIMESTAMP
type ModelWithStrID ¶
type ModelWithStrID struct { ID string `gorm:"primaryKey;" json:"id"` CreatedAt Time `gorm:"notNull;default:CURRENT_TIMESTAMP;index;comment:创建时间" json:"created_at"` UpdatedAt Time `gorm:"notNull;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` }
ModelWithStrID string id 模型
func (*ModelWithStrID) BeforeCreate ¶
func (d *ModelWithStrID) BeforeCreate(*gorm.DB) error
func (*ModelWithStrID) BeforeUpdate ¶
func (d *ModelWithStrID) BeforeUpdate(*gorm.DB) error
type Option ¶
func WithCreatedAt ¶
type QueryOption ¶
QueryOption ..
type Time ¶
func (Time) MarshalJSON ¶
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Type ¶
type Type[T any] struct { // contains filtered or unexported fields }
func (Type[T]) Update ¶
func (t Type[T]) Update(model *T, changeFn func(*T), opts ...QueryOption) error
Update 通用更新
type Universal ¶
type Universal[T any] interface { First(*T, ...QueryOption) error Update(*T, func(*T), ...QueryOption) error Delete(*T, ...QueryOption) error Create(*T) error Find(out *[]*T, p Pager, opts ...QueryOption) (int64, error) }
Universal 通用增删改查
Click to show internal directories.
Click to hide internal directories.