Categorygithub.com/go-zoox/gormx
modulepackage
1.5.6
Repository: https://github.com/go-zoox/gormx.git
Documentation: pkg.go.dev

# README

GORMX - GORM Utils

Functions

package gormx // import "github.com/go-zoox/gormx"

var Version = "1.0.0"
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 GetDB() *gorm.DB
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 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) (err error)
func Retrieve[T any](id uint) (*T, error)
func Save[T any](one *T) error
func Update[T any](id uint, uc func(*T)) (err error)
type OrderBy []OrderByOne
type OrderByOne struct{ ... }
type Page struct{ ... }
type SetWhereOptions struct{ ... }
type Where []WhereOne
type WhereOne struct{ ... }

# Packages

No description provided by the author

# Functions

Connect connects the database.
Count counts records.
CountALL counts all records.
Create creates a record.
Delete deletes the record from database by the given conditions.
DeleteOneByID deletes one record by id.
Exists returns true if the record exists.
Find finds records.
FindAll finds all records.
FindByID finds a record by id.
FindOne finds one record.
FindOneAndDelete finds one record and delete it.
FindOneAndUpdate finds one and update it.
FindOneByIDAndDelete finds one record by id and delete it.
FindOneByIDAndUpdate finds one by id and update.
FindOneByIDOrCreate finds one record by id or create a new one.
FindOneOrCreate find one or create one.
FindOneWithComplexConditions finds one record.
Get returns the model by the given id.
GetDB returns the gorm.DB instance.
GetDSN returns the database DSN.
GetEngine returns the database engine.
GetMany gets many records by ids.
GetOrCreate gets or creates a record.
Has returns true if the record exists.
IsDryRunModeUnsupportedError returns true if err is related to dry run mode unsupported error.
IsDuplicatedKeyError returns true if err is related to duplicated key error.
IsEmptySliceError returns true if err is related to empty slice error.
IsForeignKeyViolatedError returns true if err is related to foreign key violated error.
IsInvalidDataError returns true if err is related to invalid data error.
IsInvalidDBError returns true if err is related to invalid db error.
IsInvalidFieldError returns true if err is related to invalid field error.
IsInvalidTransactionError returns true if err is related to invalid transaction error.
IsInvalidValueError returns true if err is related to invalid value error.
IsInvalidValueOfLengthError returns true if err is related to invalid value of length error.
IsMissingWhereClauseError returns true if err is related to missing where clause error.
IsModelAccessibleFieldsRequiredError returns true if err is related to model accessible fields required error.
IsModelValueRequiredError returns true if err is related to model value required error.
IsNotImplementedError returns true if err is related to not implemented error.
IsPreloadNotAllowedError returns true if err is related to preload not allowed error.
IsPrimaryKeyRequiredError returns true if err is related to primary key required error.
IsRecordNotFoundError returns true if err is related to record not found error.
IsRegisteredError returns true if err is related to registered error.
IsSubQueryRequiredError returns true if err is related to sub query required error.
IsUnsupportedDriverError returns true if err is related to unsupported driver error.
IsUnsupportedRelationError returns true if err is related to unsupported relation error.
List lists records.
ListALL lists all records.
LoadDB loads the database.
Migrate migrates the models to the database.
NewParams returns the params.
Register registers the model.
Retrieve retrieves a record.
Save saves a record.
SetDB sets the global gorm.DB instance.
SQL finds one record by id or create a new one.
Update updates a record.

# Variables

ErrDryRunModeUnsupported dry run mode unsupported.
ErrDuplicatedKey occurs when there is a unique key constraint violation.
ErrEmptySlice empty slice found.
ErrForeignKeyViolated occurs when there is a foreign key constraint violation.
ErrInvalidData unsupported data.
ErrInvalidDB invalid db.
ErrInvalidField invalid field.
ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`.
ErrInvalidValue invalid value.
ErrInvalidValueOfLength invalid values do not match length.
ErrMissingWhereClause missing where clause.
ErrModelAccessibleFieldsRequired model accessible fields required.
ErrModelValueRequired model value required.
ErrNotImplemented not implemented.
ErrPreloadNotAllowed preload is not allowed when count is used.
ErrPrimaryKeyRequired primary keys required.
ErrRecordNotFound record not found error.
ErrRegistered registered.
ErrSubQueryRequired sub query required.
ErrUnsupportedDriver unsupported driver.
ErrUnsupportedRelation unsupported relations.
Version is the version of this package.

# Structs

ControllerImpl is the implementation of the Controller interface.
ListParams is the struct that wraps the basic fields.
ListParamsDefault is the struct that wraps the basic fields.
LoadDBOptions is the options for LoadDB.
ModelGeneric ...
ModelImpl is the implementation of the Model interface.
OrderByOne is a single order by.
Page is the page query.
Params is the interface that wraps the basic methods.
ServiceImpl is the implementation of the Service interface.
SetWhereOptions is the options for SetWhere.
Where is the where.
WhereOne is the where one.

# Interfaces

Controller is the interface that wraps the basic methods.
Model is the interface that wraps the basic methods.
Service is the interface that wraps the basic methods.

# Type aliases

OrderBy is a list of order bys.