Documentation
¶
Index ¶
- Constants
- Variables
- func Connection() (*sql.DB, error)
- func Init(gormdb *gorm.DB)
- type Builer
- type Clause
- func Between(field string, value any) *Clause
- func EQ(field string, value any) *Clause
- func GT(field string, value any) *Clause
- func GTE(field string, value any) *Clause
- func IN(field string, values any) *Clause
- func IsNotNull(field string) *Clause
- func IsNull(field string) *Clause
- func LT(field string, value any) *Clause
- func LTE(field string, value any) *Clause
- func Like(field, value string) *Clause
- func NOT() *Clause
- func Search(fields []string, value, operator string) *Clause
- func (w *Clause) AND() *Clause
- func (w *Clause) Between(field string, value any) *Clause
- func (w *Clause) EQ(field string, value any) *Clause
- func (w *Clause) GT(field string, value any) *Clause
- func (w *Clause) GTE(field string, value any) *Clause
- func (w *Clause) IN(field string, values any) *Clause
- func (w *Clause) IsNotNull(field string) *Clause
- func (w *Clause) IsNull(field string) *Clause
- func (w *Clause) LT(field string, value any) *Clause
- func (w *Clause) LTE(field string, value any) *Clause
- func (w *Clause) Like(field, value string) *Clause
- func (w *Clause) NOT() *Clause
- func (w *Clause) OR() *Clause
- func (w *Clause) Search(fields []string, value, operator string) *Clause
- type ConflictResovler
- type QueryConsumer
- type QueryMaker
- type RawExecutor
- type Repository
- type Transaction
Constants ¶
View Source
const ( ISOperator = "IS" ISNOTOperator = "IS NOT" EQOperator = "=" GTOperator = ">" GTEOperator = ">=" LTOperator = "<" LTEOperator = "<=" INOperator = "IN" LikeOperator = " LIKE " BetWeen = " BETWEEN " NOTOperator = " NOT " OROperator = " OR " ANDOperator = " AND " ASCOperator = " ASC" DESCOperator = " DESC" )
Variables ¶
View Source
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 )
Functions ¶
func Connection ¶
Types ¶
type Clause ¶
type Clause struct {
// contains filtered or unexported fields
}
func IN ¶
NOTE: Because of golang limition in array of any([]any) IN function used any type for values parameter instead of []any, developers must call IN function with array of any.
type ConflictResovler ¶ added in v0.2.0
type ConflictResovler[E entity] interface {
OnConflict(clause clause.OnConflict) Repository[E]
}
type QueryConsumer ¶
type QueryConsumer[E entity] interface {
Find(ctx context.Context) ([]E, error)
One(ctx context.Context) (E, error)
Count(ctx context.Context) (int64, error)
Exists(ctx context.Context) (bool, error)
Insert(ctx context.Context, entity E) error
Save(ctx context.Context, entity E) (rowsAffected int64, err error)
InsertBatch(ctx context.Context, entities []E) (rowsAffected int64, err error)
Update(ctx context.Context, entity E) (rowsAffected int64, err error)
Delete(ctx context.Context) (rowsAffected int64, err error)
InsertTx(ctx context.Context, entity E) (tx Transaction, rowsAffected int64, err error)
SaveTx(ctx context.Context, entity E) (tx Transaction, rowsAffected int64, err error)
InsertBatchTx(ctx context.Context, entities []E) (tx Transaction, rowsAffected int64, err error)
UpdateTx(ctx context.Context, entity E) (tx Transaction, rowsAffected int64, err error)
// rowsAffected param can be nil
DeleteTx(ctx context.Context) (tx Transaction, rowsAffected int64, err error)
}
type QueryMaker ¶
type QueryMaker[E entity] interface {
Where(whereClause *Clause) Repository[E]
Having(whereClause *Clause) Repository[E]
Select(cols ...string) Repository[E]
Offset(value int) Repository[E]
Limit(value int) Repository[E]
OrderBy(name string, desc bool) Repository[E]
GroupBy(name string) Repository[E]
Args() []any
IsMany() Repository[E]
Join(ent entity) Repository[E]
}
type RawExecutor ¶
type Repository ¶ added in v0.11.0
type Repository[E entity] interface {
QueryMaker[E]
QueryConsumer[E]
RawExecutor[E]
ConflictResovler[E]
SetTx(tx Transaction, commit bool) Repository[E]
}
func NewRepository ¶ added in v0.11.0
func NewRepository[E entity](ent E) Repository[E]
type Transaction ¶
Click to show internal directories.
Click to hide internal directories.