Documentation
¶
Index ¶
- func MapErr[T any, R any](collection []T, iteratee func(T, int) (R, error)) ([]R, error)
- func TransactionFrom(ctx context.Context) *gorm.DB
- func WithTransaction(ctx context.Context, tx *gorm.DB) context.Context
- type Column
- func (c Column) EQ(value any) OpOption
- func (c Column) FuzzyIn(values []T) FuzzyQueryOption
- func (c Column) GT(value any) OpOption
- func (c Column) GTE(value any) OpOption
- func (c Column) In(values []T) RangeQueryOption
- func (c Column) LT(value any) OpOption
- func (c Column) LTE(value any) OpOption
- func (c Column) NE(value any) OpOption
- func (c Column) NotIn(values []T) RangeQueryOption
- func (c Column) Update(value any) UpdateOption
- type ColumnName
- type ColumnNameGetter
- type ColumnValue
- func (cv ColumnValue[T]) CreateClauses(f *gormschema.Field) []clause.Interface
- func (cv ColumnValue[T]) DeleteClauses(f *gormschema.Field) []clause.Interface
- func (cv ColumnValue[T]) MarshalJSON() ([]byte, error)
- func (cv ColumnValue[T]) QueryClauses(f *gormschema.Field) []clause.Interface
- func (cv *ColumnValue[T]) Scan(src any) error
- func (cv *ColumnValue[T]) UnmarshalJSON(data []byte) error
- func (cv ColumnValue[T]) UpdateClauses(f *gormschema.Field) []clause.Interface
- func (cv ColumnValue[T]) Value() (driver.Value, error)
- type Executor
- type FilterOption
- type FilterOptionType
- type FuzzyQueryOption
- type JoinOptions
- type JoinedEntity
- type ListOptions
- type Model
- type ModelOption
- type OpJoinOption
- type OpOption
- type OpQueryOption
- type Option
- type PtrColumn
- func (c PtrColumn) EQ(value any) OpOption
- func (c PtrColumn[T]) FuzzyIn(values []T) FuzzyQueryOption
- func (c PtrColumn) GT(value any) OpOption
- func (c PtrColumn) GTE(value any) OpOption
- func (c PtrColumn[T]) In(values []T) RangeQueryOption
- func (c PtrColumn) LT(value any) OpOption
- func (c PtrColumn) LTE(value any) OpOption
- func (c PtrColumn) NE(value any) OpOption
- func (c PtrColumn[T]) NotIn(values []T) RangeQueryOption
- func (c PtrColumn) Update(value any) UpdateOption
- type QueryOp
- type RangeQueryOption
- type SortOption
- type SortOrder
- type TransactionFunc
- type UpdateOption
- type ValuesOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Column ¶
type Column[T any] struct { // contains filtered or unexported fields }
Column represents a column of a table.
func (Column) FuzzyIn ¶ added in v0.2.0
func (c Column) FuzzyIn(values []T) FuzzyQueryOption
func (Column) In ¶ added in v0.2.0
func (c Column) In(values []T) RangeQueryOption
func (Column) NotIn ¶ added in v0.2.0
func (c Column) NotIn(values []T) RangeQueryOption
func (Column) Update ¶ added in v0.2.0
func (c Column) Update(value any) UpdateOption
type ColumnName ¶
type ColumnName struct { Name string // contains filtered or unexported fields }
func NewColumnName ¶ added in v0.1.0
func NewColumnName(name string) ColumnName
func (ColumnName) Full ¶ added in v0.1.0
func (cn ColumnName) Full() string
func (ColumnName) GetColumnName ¶
func (cn ColumnName) GetColumnName() ColumnName
func (ColumnName) Sort ¶ added in v0.2.0
func (cn ColumnName) Sort(order SortOrder) sortOption
func (ColumnName) String ¶ added in v0.1.0
func (cn ColumnName) String() string
type ColumnNameGetter ¶ added in v0.2.0
type ColumnNameGetter interface {
GetColumnName() ColumnName
}
type ColumnValue ¶
type ColumnValue[T any] struct { V T }
func (ColumnValue[T]) CreateClauses ¶
func (cv ColumnValue[T]) CreateClauses(f *gormschema.Field) []clause.Interface
CreateClauses implements the CreateClausesInterface interface from GORM.
func (ColumnValue[T]) DeleteClauses ¶
func (cv ColumnValue[T]) DeleteClauses(f *gormschema.Field) []clause.Interface
DeleteClauses implements the DeleteClausesInterface interface from GORM.
func (ColumnValue[T]) MarshalJSON ¶
func (cv ColumnValue[T]) MarshalJSON() ([]byte, error)
func (ColumnValue[T]) QueryClauses ¶
func (cv ColumnValue[T]) QueryClauses(f *gormschema.Field) []clause.Interface
QueryClauses implements the QueryClausesInterface interface from GORM.
func (*ColumnValue[T]) Scan ¶
func (cv *ColumnValue[T]) Scan(src any) error
Scan implements the Scanner interface.
func (*ColumnValue[T]) UnmarshalJSON ¶
func (cv *ColumnValue[T]) UnmarshalJSON(data []byte) error
func (ColumnValue[T]) UpdateClauses ¶
func (cv ColumnValue[T]) UpdateClauses(f *gormschema.Field) []clause.Interface
UpdateClauses implements the UpdateClausesInterface interface from GORM.
type Executor ¶ added in v0.2.0
type Executor[T any] interface { Get(ctx context.Context) (T, error) List(ctx context.Context, opts ListOptions) ([]T, uint64, error) Update(ctx context.Context, opts ...UpdateOption) (uint64, error) Delete(ctx context.Context) error }
Executor is an interface wraps operations related to db queries.
type FilterOption ¶ added in v0.2.0
type FilterOption interface {
GetFilterOptionType() FilterOptionType
}
type FilterOptionType ¶ added in v0.2.0
type FilterOptionType string
const ( FilterOptionTypeOpQuery FilterOptionType = "OpQuery" FilterOptionTypeRangeQuery FilterOptionType = "RangeQuery" FilterOptionTypeFuzzyQuery FilterOptionType = "FuzzyQuery" )
type FuzzyQueryOption ¶
type FuzzyQueryOption interface { FilterOption ValuesOption }
FuzzyQueryOption represents a query that find data that match given patterns approximately.
func NewFuzzyQueryOption ¶
func NewFuzzyQueryOption[T any](name ColumnName, values []T) FuzzyQueryOption
type JoinOptions ¶ added in v0.1.0
type JoinOptions struct { SelectedColumns []ColumnNameGetter Conditions []OpOption }
func NewJoinOptions ¶ added in v0.1.0
func NewJoinOptions(selectedColumns []ColumnNameGetter, conditions ...OpOption) JoinOptions
type JoinedEntity ¶ added in v0.1.0
type JoinedEntity[L, R any] struct { Left L `gorm:"embedded"` Right R `gorm:"embedded"` }
type ListOptions ¶
type ListOptions struct { Offset uint64 Limit uint64 SortOptions []SortOption }
ListOptions contains options and parameters that related to data listing.
type Model ¶
type Model[T any] interface { // DB returns the db instance. DB(context.Context) *gorm.DB // Table returns the table name in the database. Table() string // Columns returns a instance of type T, // all fields of type sqldb.Column[U] in the instance are populated with corresponding column name. Columns() T // ColumnNames returns all column names the model has. ColumnNames() []ColumnNameGetter // Create creates an new entity of type T. Create(ctx context.Context, entity *T) error Query(queries ...FilterOption) Executor[T] }
Model is an interface defines commonly used methods to manipulate data.
func Join ¶ added in v0.1.0
func Join[L, R any](ctx context.Context, left Model[L], right Model[R], opts JoinOptions) Model[JoinedEntity[L, R]]
func LeftJoin ¶ added in v0.1.0
func LeftJoin[L, R any](ctx context.Context, left Model[L], right Model[R], opts JoinOptions) Model[JoinedEntity[L, R]]
type ModelOption ¶ added in v0.1.0
type ModelOption func(*modelConfig)
func WithDBInitialFunc ¶ added in v0.1.0
func WithDBInitialFunc(initial func(*gorm.DB) *gorm.DB) ModelOption
type OpJoinOption ¶ added in v0.1.0
type OpJoinOption interface { GetLeftColumnName() ColumnName GetRightColumnName() ColumnName QueryOp() QueryOp }
type OpOption ¶ added in v0.2.0
type OpOption struct { mo.Either[OpJoinOption, OpQueryOption] }
func NewOpJoinOption ¶ added in v0.1.0
func NewOpJoinOption(left ColumnName, op QueryOp, right ColumnName) OpOption
func NewOpQueryOption ¶
func NewOpQueryOption[T any](name ColumnName, op QueryOp, v T) OpOption
func (OpOption) GetFilterOptionType ¶ added in v0.2.0
func (opt OpOption) GetFilterOptionType() FilterOptionType
type OpQueryOption ¶
type OpQueryOption interface { Option FilterOption QueryOp() QueryOp }
OpQueryOption represents a query which use the given query operator to search data.
type Option ¶
type Option interface { ColumnNameGetter // GetValue returns the value the option carries. It is used by the operation to query or update the target column. GetValue() any }
Option wraps basic methods of options.
type PtrColumn ¶
type PtrColumn[T any] struct { // contains filtered or unexported fields }
PtrColumn is used when declaring models with pointer fields, for example:
type Model struct{ Name PtrColumn[string] }
equals to
type Model struct{ Name *string }
func NewPtrColumn ¶
NewPtrColumn creates a new PtrColumn of type T.
func (PtrColumn[T]) FuzzyIn ¶ added in v0.2.0
func (c PtrColumn[T]) FuzzyIn(values []T) FuzzyQueryOption
func (PtrColumn[T]) In ¶ added in v0.2.0
func (c PtrColumn[T]) In(values []T) RangeQueryOption
func (PtrColumn[T]) NotIn ¶ added in v0.2.0
func (c PtrColumn[T]) NotIn(values []T) RangeQueryOption
func (PtrColumn) Update ¶ added in v0.2.0
func (c PtrColumn) Update(value any) UpdateOption
type RangeQueryOption ¶
type RangeQueryOption interface { ValuesOption FilterOption Exclude() bool }
RangeQueryOption represents a query that find data from a given range of values.
func NewRangeQueryOption ¶
func NewRangeQueryOption[T any](name ColumnName, values []T, exclude bool) RangeQueryOption
type SortOption ¶
type SortOption interface { ColumnNameGetter GetSortOrder() SortOrder }
SortOption represents an sort operation.
func NewSortOption ¶
func NewSortOption(name ColumnName, order SortOrder) SortOption
type TransactionFunc ¶
A TransactionFunc starts a transaction.
func NewTransactionFunc ¶ added in v0.0.5
func NewTransactionFunc(db *gorm.DB) TransactionFunc
NewTransactionFunc returns a TransactionFunc.
type UpdateOption ¶
type UpdateOption interface { Option }
UpdateOption represents an update operation that updates the target column with given value.
func NewUpdateOption ¶
func NewUpdateOption[T any](name ColumnName, value T) UpdateOption
type ValuesOption ¶
type ValuesOption interface { ColumnNameGetter // GetValues returns the values the option carries. Those values are used to query data. GetValues() []any }
ValuesOption wraps basic method of options which carry multiple values.