Documentation ¶
Index ¶
- Variables
- func Connect(engine string, dsn string, opts ...func(*LoadDBOptions)) (db *gorm.DB, err error)
- func Count[T any](where *Where) (count int64, err error)
- func CountALL[T any]() (total int64, err error)
- func Create[T any](one *T) (*T, error)
- func Delete[T any](where map[any]any) (err error)
- func DeleteOneByID[T any](id uint) (err error)
- func Exists[T any](where map[any]any) (bool, error)
- func Find[T any](page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
- func FindAll[T any](where *Where, orderBy *OrderBy) (data []*T, err error)
- func FindByID[T any](id uint) (*T, error)
- func FindOne[T any](where map[any]any) (*T, error)
- func FindOneAndDelete[T any](where map[any]any) (*T, error)
- func FindOneAndUpdate[T any](where map[any]any, callback func(*T)) (*T, error)
- func FindOneByIDAndDelete[T any](id uint) (*T, error)
- func FindOneByIDAndUpdate[T any](id uint, callback func(*T)) (*T, error)
- func FindOneByIDOrCreate[T any](id uint, callback func(*T)) (*T, error)
- func FindOneOrCreate[T any](where map[any]any, callback func(*T)) (*T, error)
- func FindOneWithComplexConditions[T any](where *Where, orderBy *OrderBy) (*T, error)
- func Get[T any](id string) T
- func GetDB() *gorm.DB
- func GetDSN() string
- func GetEngine() string
- func GetMany[T any](ids []uint) (data []*T, err error)
- func GetOrCreate[T any](where map[any]any, callback func(*T)) (*T, error)
- func Has[T any](where map[string]any) bool
- func IsDryRunModeUnsupportedError(err error) bool
- func IsDuplicatedKeyError(err error) bool
- func IsEmptySliceError(err error) bool
- func IsForeignKeyViolatedError(err error) bool
- func IsInvalidDBError(err error) bool
- func IsInvalidDataError(err error) bool
- func IsInvalidFieldError(err error) bool
- func IsInvalidTransactionError(err error) bool
- func IsInvalidValueError(err error) bool
- func IsInvalidValueOfLengthError(err error) bool
- func IsMissingWhereClauseError(err error) bool
- func IsModelAccessibleFieldsRequiredError(err error) bool
- func IsModelValueRequiredError(err error) bool
- func IsNotImplementedError(err error) bool
- func IsPreloadNotAllowedError(err error) bool
- func IsPrimaryKeyRequiredError(err error) bool
- func IsRecordNotFoundError(err error) bool
- func IsRegisteredError(err error) bool
- func IsSubQueryRequiredError(err error) bool
- func IsUnsupportedDriverError(err error) bool
- func IsUnsupportedRelationError(err error) bool
- func List[T any](page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
- func ListALL[T any](where *Where, orderBy *OrderBy) (data []*T, err error)
- func LoadDB(engine string, dsn string, opts ...func(*LoadDBOptions)) (err error)
- func Migrate()
- func Register(name string, m Model)
- func Retrieve[T any](id uint) (*T, error)
- func SQL[T any](sql string, values ...any) (*T, error)
- func Save[T any](one *T) error
- func SetDB(d *gorm.DB)
- func Update[T any](id uint, uc func(*T)) (err error)
- type Controller
- type ControllerImpl
- type ListParams
- type ListParamsDefault
- type LoadDBOptions
- type Model
- type ModelGeneric
- func (m *ModelGeneric[T]) Create(one *T) (*T, error)
- func (m *ModelGeneric[T]) Delete(id uint) (err error)
- func (m *ModelGeneric[T]) Exists(where map[any]any) (bool, error)
- func (m *ModelGeneric[T]) FindAll(where *Where, orderBy *OrderBy) ([]*T, error)
- func (m *ModelGeneric[T]) FindByID(id uint) (*T, error)
- func (m *ModelGeneric[T]) FindOne(where map[any]any) (*T, error)
- func (m *ModelGeneric[T]) FindOneAndDelete(where map[any]any) (*T, error)
- func (m *ModelGeneric[T]) FindOneAndUpdate(where map[any]any, callback func(*T)) (*T, error)
- func (m *ModelGeneric[T]) FindOneOrCreate(where map[any]any, callback func(*T)) (*T, error)
- func (m *ModelGeneric[T]) GetMany(ids []uint) (data []*T, err error)
- func (m *ModelGeneric[T]) List(page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
- func (m *ModelGeneric[T]) Retrieve(id uint) (*T, error)
- func (m *ModelGeneric[T]) Save() error
- func (m *ModelGeneric[T]) Update(id uint, uc func(*T)) (err error)
- type ModelImpl
- type OrderBy
- type OrderByOne
- type Page
- type Params
- type Service
- type ServiceImpl
- type SetWhereOptions
- type Where
- func (w *Where) Add(key string, value interface{}, opts ...*SetWhereOptions)
- func (w *Where) Build() (query string, args []interface{}, err error)
- func (w *Where) Debug()
- func (w *Where) Del(key string)
- func (w *Where) Get(key string) (interface{}, bool)
- func (w *Where) Length() int
- func (w *Where) Reset()
- func (w *Where) Set(key string, value interface{}, opts ...*SetWhereOptions)
- type WhereOne
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRecordNotFound record not found error ErrRecordNotFound = gorm.ErrRecordNotFound // ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback` ErrInvalidTransaction = gorm.ErrInvalidTransaction // ErrNotImplemented not implemented ErrNotImplemented = gorm.ErrNotImplemented // ErrMissingWhereClause missing where clause ErrMissingWhereClause = gorm.ErrMissingWhereClause // ErrUnsupportedRelation unsupported relations ErrUnsupportedRelation = gorm.ErrUnsupportedRelation // ErrPrimaryKeyRequired primary keys required ErrPrimaryKeyRequired = gorm.ErrPrimaryKeyRequired // ErrModelValueRequired model value required ErrModelValueRequired = gorm.ErrModelValueRequired // ErrModelAccessibleFieldsRequired model accessible fields required ErrModelAccessibleFieldsRequired = gorm.ErrModelAccessibleFieldsRequired // ErrSubQueryRequired sub query required ErrSubQueryRequired = gorm.ErrSubQueryRequired // ErrInvalidData unsupported data ErrInvalidData = gorm.ErrInvalidData // ErrUnsupportedDriver unsupported driver ErrUnsupportedDriver = gorm.ErrUnsupportedDriver // ErrRegistered registered ErrRegistered = gorm.ErrRegistered // ErrInvalidField invalid field ErrInvalidField = gorm.ErrInvalidField // ErrEmptySlice empty slice found ErrEmptySlice = gorm.ErrEmptySlice // ErrDryRunModeUnsupported dry run mode unsupported ErrDryRunModeUnsupported = gorm.ErrDryRunModeUnsupported // ErrInvalidDB invalid db ErrInvalidDB = gorm.ErrInvalidDB // ErrInvalidValue invalid value ErrInvalidValue = gorm.ErrInvalidValue // ErrInvalidValueOfLength invalid values do not match length ErrInvalidValueOfLength = gorm.ErrInvalidValueOfLength // ErrPreloadNotAllowed preload is not allowed when count is used ErrPreloadNotAllowed = gorm.ErrPreloadNotAllowed // ErrDuplicatedKey occurs when there is a unique key constraint violation ErrDuplicatedKey = gorm.ErrDuplicatedKey // ErrForeignKeyViolated occurs when there is a foreign key constraint violation ErrForeignKeyViolated = gorm.ErrForeignKeyViolated )
var Version = "1.5.3"
Version is the version of this package.
Functions ¶
func DeleteOneByID ¶
DeleteOneByID deletes one record by id.
func Find ¶
func Find[T any](page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
Find finds records.
func FindOneAndDelete ¶
FindOneAndDelete finds one record and delete it.
func FindOneAndUpdate ¶
FindOneAndUpdate finds one and update it.
func FindOneByIDAndDelete ¶
FindOneByIDAndDelete finds one record by id and delete it.
func FindOneByIDAndUpdate ¶
FindOneByIDAndUpdate finds one by id and update.
func FindOneByIDOrCreate ¶
FindOneByIDOrCreate finds one record by id or create a new one.
func FindOneOrCreate ¶
FindOneOrCreate find one or create one.
func FindOneWithComplexConditions ¶ added in v1.4.2
FindOneWithComplexConditions finds one record.
func GetOrCreate ¶
GetOrCreate gets or creates a record.
func IsDryRunModeUnsupportedError ¶ added in v1.0.9
IsDryRunModeUnsupportedError returns true if err is related to dry run mode unsupported error
func IsDuplicatedKeyError ¶ added in v1.0.9
IsDuplicatedKeyError returns true if err is related to duplicated key error
func IsEmptySliceError ¶ added in v1.0.9
IsEmptySliceError returns true if err is related to empty slice error
func IsForeignKeyViolatedError ¶ added in v1.0.9
IsForeignKeyViolatedError returns true if err is related to foreign key violated error
func IsInvalidDBError ¶ added in v1.0.9
IsInvalidDBError returns true if err is related to invalid db error
func IsInvalidDataError ¶ added in v1.0.9
IsInvalidDataError returns true if err is related to invalid data error
func IsInvalidFieldError ¶ added in v1.0.9
IsInvalidFieldError returns true if err is related to invalid field error
func IsInvalidTransactionError ¶ added in v1.0.9
IsInvalidTransactionError returns true if err is related to invalid transaction error
func IsInvalidValueError ¶ added in v1.0.9
IsInvalidValueError returns true if err is related to invalid value error
func IsInvalidValueOfLengthError ¶ added in v1.0.9
IsInvalidValueOfLengthError returns true if err is related to invalid value of length error
func IsMissingWhereClauseError ¶ added in v1.0.9
IsMissingWhereClauseError returns true if err is related to missing where clause error
func IsModelAccessibleFieldsRequiredError ¶ added in v1.0.9
IsModelAccessibleFieldsRequiredError returns true if err is related to model accessible fields required error
func IsModelValueRequiredError ¶ added in v1.0.9
IsModelValueRequiredError returns true if err is related to model value required error
func IsNotImplementedError ¶ added in v1.0.9
IsNotImplementedError returns true if err is related to not implemented error
func IsPreloadNotAllowedError ¶ added in v1.0.9
IsPreloadNotAllowedError returns true if err is related to preload not allowed error
func IsPrimaryKeyRequiredError ¶ added in v1.0.9
IsPrimaryKeyRequiredError returns true if err is related to primary key required error
func IsRecordNotFoundError ¶ added in v1.0.9
IsRecordNotFoundError returns true if err is related to record not found error
func IsRegisteredError ¶ added in v1.0.9
IsRegisteredError returns true if err is related to registered error
func IsSubQueryRequiredError ¶ added in v1.0.9
IsSubQueryRequiredError returns true if err is related to sub query required error
func IsUnsupportedDriverError ¶ added in v1.0.9
IsUnsupportedDriverError returns true if err is related to unsupported driver error
func IsUnsupportedRelationError ¶ added in v1.0.9
IsUnsupportedRelationError returns true if err is related to unsupported relation error
func List ¶
func List[T any](page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
List lists records.
func LoadDB ¶
func LoadDB(engine string, dsn string, opts ...func(*LoadDBOptions)) (err error)
LoadDB loads the database
Types ¶
type Controller ¶ added in v1.0.5
Controller is the interface that wraps the basic methods.
type ControllerImpl ¶ added in v1.0.5
type ControllerImpl struct { }
ControllerImpl is the implementation of the Controller interface.
type ListParams ¶ added in v1.0.7
ListParams is the struct that wraps the basic fields.
type ListParamsDefault ¶ added in v1.0.7
ListParamsDefault is the struct that wraps the basic fields.
type LoadDBOptions ¶ added in v1.0.3
LoadDBOptions is the options for LoadDB
type ModelGeneric ¶ added in v1.0.10
type ModelGeneric[T any] struct { }
ModelGeneric ...
func (*ModelGeneric[T]) Create ¶ added in v1.0.10
func (m *ModelGeneric[T]) Create(one *T) (*T, error)
Create ...
func (*ModelGeneric[T]) Delete ¶ added in v1.0.10
func (m *ModelGeneric[T]) Delete(id uint) (err error)
Delete ...
func (*ModelGeneric[T]) Exists ¶ added in v1.0.10
func (m *ModelGeneric[T]) Exists(where map[any]any) (bool, error)
Exists ...
func (*ModelGeneric[T]) FindAll ¶ added in v1.0.10
func (m *ModelGeneric[T]) FindAll(where *Where, orderBy *OrderBy) ([]*T, error)
FindAll ...
func (*ModelGeneric[T]) FindByID ¶ added in v1.0.10
func (m *ModelGeneric[T]) FindByID(id uint) (*T, error)
FindByID ...
func (*ModelGeneric[T]) FindOne ¶ added in v1.0.10
func (m *ModelGeneric[T]) FindOne(where map[any]any) (*T, error)
FindOne ...
func (*ModelGeneric[T]) FindOneAndDelete ¶ added in v1.0.10
func (m *ModelGeneric[T]) FindOneAndDelete(where map[any]any) (*T, error)
FindOneAndDelete ...
func (*ModelGeneric[T]) FindOneAndUpdate ¶ added in v1.0.10
func (m *ModelGeneric[T]) FindOneAndUpdate(where map[any]any, callback func(*T)) (*T, error)
FindOneAndUpdate ...
func (*ModelGeneric[T]) FindOneOrCreate ¶ added in v1.0.10
func (m *ModelGeneric[T]) FindOneOrCreate(where map[any]any, callback func(*T)) (*T, error)
FindOneOrCreate ...
func (*ModelGeneric[T]) GetMany ¶ added in v1.0.10
func (m *ModelGeneric[T]) GetMany(ids []uint) (data []*T, err error)
GetMany ...
func (*ModelGeneric[T]) List ¶ added in v1.0.10
func (m *ModelGeneric[T]) List(page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
List ...
func (*ModelGeneric[T]) Retrieve ¶ added in v1.0.10
func (m *ModelGeneric[T]) Retrieve(id uint) (*T, error)
Retrieve ...
func (*ModelGeneric[T]) Update ¶ added in v1.0.10
func (m *ModelGeneric[T]) Update(id uint, uc func(*T)) (err error)
Update ...
type ModelImpl ¶ added in v1.0.5
type ModelImpl struct { ID uint `gorm:"primarykey" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` // Creator uint `json:"creator"` Modifier uint `json:"modifier"` }
ModelImpl is the implementation of the Model interface.
type OrderByOne ¶
OrderByOne is a single order by.
type Page ¶
type Page struct { Page int64 `query:"page,default=1"` PageSize int64 `query:"pageSize,default=10"` }
Page is the page query.
type Params ¶ added in v1.0.7
type Params struct {
// contains filtered or unexported fields
}
Params is the interface that wraps the basic methods.
func (*Params) GetList ¶ added in v1.0.7
func (c *Params) GetList(defaults ...*ListParamsDefault) (*ListParams, error)
GetList is the struct that wraps the basic fields.
type Service ¶ added in v1.0.5
type Service interface {
Name() string
}
Service is the interface that wraps the basic methods.
type ServiceImpl ¶ added in v1.0.5
type ServiceImpl struct { }
ServiceImpl is the implementation of the Service interface.
func (*ServiceImpl) Name ¶ added in v1.0.5
func (s *ServiceImpl) Name() string
Name returns the name of the service.
type SetWhereOptions ¶
type SetWhereOptions struct { IsEqual bool IsNotEqual bool IsFuzzy bool IsIn bool IsNotIn bool IsPlain bool IsFullTextSearch bool FullTextSearchFields []string }
SetWhereOptions is the options for SetWhere.
type Where ¶
Where is the where.
func (*Where) Add ¶ added in v1.5.1
func (w *Where) Add(key string, value interface{}, opts ...*SetWhereOptions)
Add adds a where, if exists, append.
func (*Where) Set ¶
func (w *Where) Set(key string, value interface{}, opts ...*SetWhereOptions)
Set sets a where, if exists, update.
type WhereOne ¶
type WhereOne struct { Key string Value interface{} // IsEqual => = IsEqual bool // IsNotEqual => != IsNotEqual bool // IsFuzzy => ILike IsFuzzy bool // IsIn => in (?) IsIn bool // IsNotIn => not in (?) IsNotIn bool // IsPlain => plain IsPlain bool // IsFullTextSearch => ILike (field1) OR ILike (field2) OR ... IsFullTextSearch bool FullTextSearchFields []string }
WhereOne is the where one.
Source Files ¶
- count.go
- create.go
- db.go
- delete.go
- delete_one_by_id.go
- errors.go
- exists.go
- find.go
- find_all.go
- find_by_id.go
- find_one.go
- find_one_and_delete.go
- find_one_and_update.go
- find_one_by_id_and_delete.go
- find_one_by_id_and_update.go
- find_one_by_id_or_create.go
- find_one_or_create.go
- generic_controller.go
- generic_model.go
- generic_service.go
- get_many.go
- get_or_create.go
- has.go
- ioc.go
- list.go
- list_all.go
- migrate.go
- order_by.go
- page.go
- params.go
- register.go
- retrieve.go
- save.go
- sql.go
- update.go
- version.go
- where.go