Documentation
¶
Index ¶
- Variables
- func Aggregate[T any](field string, where *Where, operations []string) (map[string]interface{}, error)
- func Avg[T any](field string, where *Where) (float64, error)
- 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 CountDistinct[T any](field string, where *Where) (int64, error)
- func Create[T any](one *T) (*T, error)
- func Delete[T any, W WhereCondition](where W) (err error)
- func DeleteOneByID[T any](id uint) (err error)
- func Exists[T any, W WhereCondition](where W) (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, W WhereCondition](where W) (*T, error)
- func FindOneAndDelete[T any, W WhereCondition](where W) (*T, error)
- func FindOneAndUpdate[T any, W WhereCondition](where W, 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, W WhereCondition](where W, 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 GetFieldType[T any](field string) (reflect.Type, error)
- func GetMany[T any](ids []uint) (data []*T, err error)
- func GetOrCreate[T any, W WhereCondition](where W, 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 Max[T any](field string, where *Where) (interface{}, error)
- func Migrate()
- func Min[T any](field string, where *Where) (interface{}, error)
- 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 Sum[T any](field string, where *Where) (float64, error)
- func Update[T any](id uint, uc func(*T)) (err error)
- type AggregateResult
- type Controller
- type ControllerImpl
- type Date
- type GroupByResult
- type JSON
- type JSONArray
- type JSONObject
- type JoinClause
- 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
- func (w *OrderBy) Add(key string, IsDESC bool)
- func (w *OrderBy) AddClause(clause string)
- func (w *OrderBy) Build() string
- func (w *OrderBy) Debug()
- func (w *OrderBy) Del(key string)
- func (w *OrderBy) Get(key string) (bool, bool)
- func (w *OrderBy) GetClause(key string) string
- func (w *OrderBy) Length() int
- func (w *OrderBy) Reset()
- func (w *OrderBy) Set(key string, IsDESC bool)
- type OrderByOne
- type Page
- type Params
- type QueryBuilder
- func (q *QueryBuilder[T]) Avg(field string) (float64, error)
- func (q *QueryBuilder[T]) Chunk(chunkSize int, callback func([]*T) error) error
- func (q *QueryBuilder[T]) Clone() *QueryBuilder[T]
- func (q *QueryBuilder[T]) Count() (int64, error)
- func (q *QueryBuilder[T]) Create(value *T) error
- func (q *QueryBuilder[T]) CreateInBatches(values []*T, batchSize int) error
- func (q *QueryBuilder[T]) Delete() error
- func (q *QueryBuilder[T]) Distinct() *QueryBuilder[T]
- func (q *QueryBuilder[T]) Exists() (bool, error)
- func (q *QueryBuilder[T]) Find() ([]*T, error)
- func (q *QueryBuilder[T]) FindInBatches(batchSize int, fn func(tx *gorm.DB, batch int) error) error
- func (q *QueryBuilder[T]) First() (*T, error)
- func (q *QueryBuilder[T]) GetDB() *gorm.DB
- func (q *QueryBuilder[T]) GetTableName() string
- func (q *QueryBuilder[T]) GroupBy(fields ...string) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Having(field string, value interface{}, opts ...*SetWhereOptions) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Join(table, condition string, args ...interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Last() (*T, error)
- func (q *QueryBuilder[T]) LeftJoin(table, condition string, args ...interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Limit(limit int) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Max(field string) (interface{}, error)
- func (q *QueryBuilder[T]) Min(field string) (interface{}, error)
- func (q *QueryBuilder[T]) Offset(offset int) *QueryBuilder[T]
- func (q *QueryBuilder[T]) OrderBy(field string, desc ...bool) *QueryBuilder[T]
- func (q *QueryBuilder[T]) OrderByAsc(field string) *QueryBuilder[T]
- func (q *QueryBuilder[T]) OrderByDesc(field string) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Page(page, pageSize int) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Paginate(page, pageSize int) ([]*T, int64, error)
- func (q *QueryBuilder[T]) Pluck(column string, dest interface{}) error
- func (q *QueryBuilder[T]) Preload(associations ...string) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Raw(sql string, values ...interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) RightJoin(table, condition string, args ...interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Save(value *T) error
- func (q *QueryBuilder[T]) Scan(dest interface{}) error
- func (q *QueryBuilder[T]) Select(columns ...string) *QueryBuilder[T]
- func (q *QueryBuilder[T]) Sum(field string) (float64, error)
- func (q *QueryBuilder[T]) ToSQL() (string, error)
- func (q *QueryBuilder[T]) Transaction(fn func(tx *QueryBuilder[T]) error) error
- func (q *QueryBuilder[T]) Update(updates map[string]interface{}) error
- func (q *QueryBuilder[T]) UpdateColumn(updates map[string]interface{}) error
- func (q *QueryBuilder[T]) Where(field string, value interface{}, opts ...*SetWhereOptions) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereBetween(field string, start, end interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereEqual(field string, value interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereIn(field string, values interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereLike(field string, value string) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereNotEqual(field string, value interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereNotIn(field string, values interface{}) *QueryBuilder[T]
- func (q *QueryBuilder[T]) WhereRaw(sql string, args ...interface{}) *QueryBuilder[T]
- type RangeMode
- type Service
- type ServiceImpl
- type SetWhereOptions
- type UUID
- 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 WhereCondition
- 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.6.1"
Version is the version of this package.
Functions ¶
func Aggregate ¶ added in v1.6.0
func Aggregate[T any](field string, where *Where, operations []string) (map[string]interface{}, error)
Aggregate performs multiple aggregate operations in a single query
func CountDistinct ¶ added in v1.6.0
CountDistinct counts distinct values of a field
func Delete ¶
func Delete[T any, W WhereCondition](where W) (err error)
Delete deletes the record from database by the given conditions. Supports both map[any]any and *Where as where condition.
func DeleteOneByID ¶
DeleteOneByID deletes one record by id.
func Exists ¶
func Exists[T any, W WhereCondition](where W) (bool, error)
Exists returns true if the record exists. Supports both map[any]any and *Where as where condition.
func Find ¶
func Find[T any](page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)
Find finds records.
func FindOne ¶
func FindOne[T any, W WhereCondition](where W) (*T, error)
FindOne finds one record. Supports both map[any]any and *Where as where condition.
func FindOneAndDelete ¶
func FindOneAndDelete[T any, W WhereCondition](where W) (*T, error)
FindOneAndDelete finds one record and delete it. Supports both map[any]any and *Where as where condition.
func FindOneAndUpdate ¶
func FindOneAndUpdate[T any, W WhereCondition](where W, callback func(*T)) (*T, error)
FindOneAndUpdate finds one and update it. Supports both map[any]any and *Where as where condition.
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 ¶
func FindOneOrCreate[T any, W WhereCondition](where W, callback func(*T)) (*T, error)
FindOneOrCreate find one or create one. Supports both map[any]any and *Where as where condition.
func FindOneWithComplexConditions ¶ added in v1.4.2
FindOneWithComplexConditions finds one record.
func GetFieldType ¶ added in v1.6.0
GetFieldType returns the type of a field in a struct
func GetOrCreate ¶
func GetOrCreate[T any, W WhereCondition](where W, callback func(*T)) (*T, error)
GetOrCreate gets or creates a record. Supports both map[any]any and *Where as where condition.
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
func SetDB ¶ added in v1.5.3
SetDB sets the global gorm.DB instance. This is useful for old projects that already use gorm.
Types ¶
type AggregateResult ¶ added in v1.6.0
type AggregateResult struct {
Value interface{}
Error error
}
AggregateResult represents the result of an aggregate query
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 GroupByResult ¶ added in v1.6.0
type GroupByResult struct {
Group map[string]interface{}
Count int64
Sum float64
Avg float64
Min interface{}
Max interface{}
}
GroupByResult represents the result of a group by query
type JoinClause ¶ added in v1.6.0
type JoinClause struct {
Type string // "INNER", "LEFT", "RIGHT", "FULL"
Table string
Condition string
Args []interface{}
}
JoinClause represents a join clause
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 OrderBy ¶
type OrderBy []OrderByOne
OrderBy is a list of order bys.
type OrderByOne ¶
OrderByOne is a single order by.
func (*OrderByOne) Clause ¶ added in v1.5.8
func (w *OrderByOne) Clause() string
Clause returns the clause of the order by.
func (*OrderByOne) String ¶ added in v1.5.8
func (w *OrderByOne) String() string
String returns the string of the 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 QueryBuilder ¶ added in v1.6.0
type QueryBuilder[T any] struct { // contains filtered or unexported fields }
QueryBuilder provides a fluent interface for building database queries
func NewQuery ¶ added in v1.6.0
func NewQuery[T any]() *QueryBuilder[T]
NewQuery creates a new query builder for the given model type
func (*QueryBuilder[T]) Avg ¶ added in v1.6.0
func (q *QueryBuilder[T]) Avg(field string) (float64, error)
Avg calculates the average of a field
func (*QueryBuilder[T]) Chunk ¶ added in v1.6.0
func (q *QueryBuilder[T]) Chunk(chunkSize int, callback func([]*T) error) error
Chunk processes records in chunks
func (*QueryBuilder[T]) Clone ¶ added in v1.6.0
func (q *QueryBuilder[T]) Clone() *QueryBuilder[T]
Clone creates a copy of the query builder
func (*QueryBuilder[T]) Count ¶ added in v1.6.0
func (q *QueryBuilder[T]) Count() (int64, error)
Count executes the query and returns the count of matching records
func (*QueryBuilder[T]) Create ¶ added in v1.6.0
func (q *QueryBuilder[T]) Create(value *T) error
Create inserts a new record
func (*QueryBuilder[T]) CreateInBatches ¶ added in v1.6.0
func (q *QueryBuilder[T]) CreateInBatches(values []*T, batchSize int) error
CreateInBatches inserts records in batches
func (*QueryBuilder[T]) Delete ¶ added in v1.6.0
func (q *QueryBuilder[T]) Delete() error
Delete executes the query and deletes all matching records
func (*QueryBuilder[T]) Distinct ¶ added in v1.6.0
func (q *QueryBuilder[T]) Distinct() *QueryBuilder[T]
Distinct adds a DISTINCT clause
func (*QueryBuilder[T]) Exists ¶ added in v1.6.0
func (q *QueryBuilder[T]) Exists() (bool, error)
Exists checks if any records match the query conditions
func (*QueryBuilder[T]) Find ¶ added in v1.6.0
func (q *QueryBuilder[T]) Find() ([]*T, error)
Find executes the query and returns all matching records
func (*QueryBuilder[T]) FindInBatches ¶ added in v1.6.0
FindInBatches processes records in batches
func (*QueryBuilder[T]) First ¶ added in v1.6.0
func (q *QueryBuilder[T]) First() (*T, error)
First executes the query and returns the first matching record
func (*QueryBuilder[T]) GetDB ¶ added in v1.6.0
func (q *QueryBuilder[T]) GetDB() *gorm.DB
GetDB returns the underlying GORM DB instance
func (*QueryBuilder[T]) GetTableName ¶ added in v1.6.0
func (q *QueryBuilder[T]) GetTableName() string
GetTableName returns the table name for the model
func (*QueryBuilder[T]) GroupBy ¶ added in v1.6.0
func (q *QueryBuilder[T]) GroupBy(fields ...string) *QueryBuilder[T]
GroupBy adds a GROUP BY clause
func (*QueryBuilder[T]) Having ¶ added in v1.6.0
func (q *QueryBuilder[T]) Having(field string, value interface{}, opts ...*SetWhereOptions) *QueryBuilder[T]
Having adds a HAVING clause
func (*QueryBuilder[T]) Join ¶ added in v1.6.0
func (q *QueryBuilder[T]) Join(table, condition string, args ...interface{}) *QueryBuilder[T]
Join adds a JOIN clause
func (*QueryBuilder[T]) Last ¶ added in v1.6.0
func (q *QueryBuilder[T]) Last() (*T, error)
Last executes the query and returns the last matching record
func (*QueryBuilder[T]) LeftJoin ¶ added in v1.6.0
func (q *QueryBuilder[T]) LeftJoin(table, condition string, args ...interface{}) *QueryBuilder[T]
LeftJoin adds a LEFT JOIN clause
func (*QueryBuilder[T]) Limit ¶ added in v1.6.0
func (q *QueryBuilder[T]) Limit(limit int) *QueryBuilder[T]
Limit sets the LIMIT clause
func (*QueryBuilder[T]) Max ¶ added in v1.6.0
func (q *QueryBuilder[T]) Max(field string) (interface{}, error)
Max finds the maximum value of a field
func (*QueryBuilder[T]) Min ¶ added in v1.6.0
func (q *QueryBuilder[T]) Min(field string) (interface{}, error)
Min finds the minimum value of a field
func (*QueryBuilder[T]) Offset ¶ added in v1.6.0
func (q *QueryBuilder[T]) Offset(offset int) *QueryBuilder[T]
Offset sets the OFFSET clause
func (*QueryBuilder[T]) OrderBy ¶ added in v1.6.0
func (q *QueryBuilder[T]) OrderBy(field string, desc ...bool) *QueryBuilder[T]
OrderBy adds an ORDER BY clause
func (*QueryBuilder[T]) OrderByAsc ¶ added in v1.6.0
func (q *QueryBuilder[T]) OrderByAsc(field string) *QueryBuilder[T]
OrderByAsc adds an ascending ORDER BY clause
func (*QueryBuilder[T]) OrderByDesc ¶ added in v1.6.0
func (q *QueryBuilder[T]) OrderByDesc(field string) *QueryBuilder[T]
OrderByDesc adds a descending ORDER BY clause
func (*QueryBuilder[T]) Page ¶ added in v1.6.0
func (q *QueryBuilder[T]) Page(page, pageSize int) *QueryBuilder[T]
Page sets both LIMIT and OFFSET for pagination
func (*QueryBuilder[T]) Paginate ¶ added in v1.6.0
func (q *QueryBuilder[T]) Paginate(page, pageSize int) ([]*T, int64, error)
Paginate returns paginated results with total count
func (*QueryBuilder[T]) Pluck ¶ added in v1.6.0
func (q *QueryBuilder[T]) Pluck(column string, dest interface{}) error
Pluck retrieves a single column as a slice
func (*QueryBuilder[T]) Preload ¶ added in v1.6.0
func (q *QueryBuilder[T]) Preload(associations ...string) *QueryBuilder[T]
Preload adds a PRELOAD clause for eager loading associations
func (*QueryBuilder[T]) Raw ¶ added in v1.6.0
func (q *QueryBuilder[T]) Raw(sql string, values ...interface{}) *QueryBuilder[T]
Raw executes a raw SQL query and returns the result
func (*QueryBuilder[T]) RightJoin ¶ added in v1.6.0
func (q *QueryBuilder[T]) RightJoin(table, condition string, args ...interface{}) *QueryBuilder[T]
RightJoin adds a RIGHT JOIN clause
func (*QueryBuilder[T]) Save ¶ added in v1.6.0
func (q *QueryBuilder[T]) Save(value *T) error
Save saves the record (insert if not exists, update if exists)
func (*QueryBuilder[T]) Scan ¶ added in v1.6.0
func (q *QueryBuilder[T]) Scan(dest interface{}) error
Scan executes the query and scans the result into the provided destination
func (*QueryBuilder[T]) Select ¶ added in v1.6.0
func (q *QueryBuilder[T]) Select(columns ...string) *QueryBuilder[T]
Select specifies the columns to be selected
func (*QueryBuilder[T]) Sum ¶ added in v1.6.0
func (q *QueryBuilder[T]) Sum(field string) (float64, error)
Sum calculates the sum of a field
func (*QueryBuilder[T]) ToSQL ¶ added in v1.6.0
func (q *QueryBuilder[T]) ToSQL() (string, error)
ToSQL returns the generated SQL query as a string (for debugging)
func (*QueryBuilder[T]) Transaction ¶ added in v1.6.0
func (q *QueryBuilder[T]) Transaction(fn func(tx *QueryBuilder[T]) error) error
Transaction executes a function within a database transaction
func (*QueryBuilder[T]) Update ¶ added in v1.6.0
func (q *QueryBuilder[T]) Update(updates map[string]interface{}) error
Update executes the query and updates all matching records
func (*QueryBuilder[T]) UpdateColumn ¶ added in v1.6.0
func (q *QueryBuilder[T]) UpdateColumn(updates map[string]interface{}) error
UpdateColumn executes the query and updates specific columns
func (*QueryBuilder[T]) Where ¶ added in v1.6.0
func (q *QueryBuilder[T]) Where(field string, value interface{}, opts ...*SetWhereOptions) *QueryBuilder[T]
Where adds a WHERE condition to the query
func (*QueryBuilder[T]) WhereBetween ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereBetween(field string, start, end interface{}) *QueryBuilder[T]
WhereBetween adds a BETWEEN WHERE condition
func (*QueryBuilder[T]) WhereEqual ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereEqual(field string, value interface{}) *QueryBuilder[T]
WhereEqual adds an equality WHERE condition
func (*QueryBuilder[T]) WhereIn ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereIn(field string, values interface{}) *QueryBuilder[T]
WhereIn adds an IN WHERE condition
func (*QueryBuilder[T]) WhereLike ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereLike(field string, value string) *QueryBuilder[T]
WhereLike adds a LIKE WHERE condition
func (*QueryBuilder[T]) WhereNotEqual ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereNotEqual(field string, value interface{}) *QueryBuilder[T]
WhereNotEqual adds a not equal WHERE condition
func (*QueryBuilder[T]) WhereNotIn ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereNotIn(field string, values interface{}) *QueryBuilder[T]
WhereNotIn adds a NOT IN WHERE condition
func (*QueryBuilder[T]) WhereRaw ¶ added in v1.6.0
func (q *QueryBuilder[T]) WhereRaw(sql string, args ...interface{}) *QueryBuilder[T]
WhereRaw adds a raw WHERE condition
type RangeMode ¶ added in v1.6.1
type RangeMode string
RangeMode defines the type of range query
const ( // RangeModeClosed represents [A, B] - both inclusive (default) RangeModeClosed RangeMode = "closed" // RangeModeOpen represents (A, B) - both exclusive RangeModeOpen RangeMode = "open" // RangeModeLeftClosed represents [A, B) - left inclusive, right exclusive RangeModeLeftClosed RangeMode = "left_closed" // RangeModeRightClosed represents (A, B] - left exclusive, right inclusive RangeModeRightClosed RangeMode = "right_closed" )
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
IsRange bool
RangeMode RangeMode // Range mode: closed (default), open, left_closed, right_closed
IsGreaterThan bool
IsLessThan bool
IsGreaterOrEqualThan bool
IsLessOrEqualThan bool
IsFullTextSearch bool
FullTextSearchFields []string
}
SetWhereOptions is the options for SetWhere.
type Where ¶
Where is the where.
func ToWhere ¶ added in v1.6.0
func ToWhere[T WhereCondition](condition T) *Where
ToWhere converts a where condition to *Where. If the input is already *Where, return it directly. If the input is map[any]any, convert it to *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 WhereCondition ¶ added in v1.6.0
WhereCondition is a type constraint for where conditions. It can be either map[any]any or *Where.
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
// IsRange => BETWEEN ? AND ? (or other range modes)
IsRange bool
// IsGreaterThan => >
IsGreaterThan bool
// IsLessThan => <
IsLessThan bool
// IsGreaterOrEqualThan => >=
IsGreaterOrEqualThan bool
// IsLessOrEqualThan => <=
IsLessOrEqualThan bool
// IsFullTextSearch => ILike (field1) OR ILike (field2) OR ...
IsFullTextSearch bool
FullTextSearchFields []string
// contains filtered or unexported fields
}
WhereOne is the where one.
Source Files
¶
- aggregate.go
- chain.go
- count.go
- create.go
- datatypes.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
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
aggregate
command
|
|
|
chain
command
|
|
|
where_comparison
command
|
|
|
where_generic
command
|
|
|
where_generic_all
command
|
|
|
where_range
command
|
|
|
where_range_modes
command
|