Documentation
¶
Index ¶
- Variables
- func AttachRelation[T, U model.Modelable](ctx context.Context, entries []T, getRelationId func(m T) *int64, ...) error
- func NewRepoError(err, internal error) error
- type AttachFunc
- type Connection
- type Ex
- type ExOr
- type Expression
- type GenericStore
- type GenericStoreImpl
- func (s *GenericStoreImpl[T]) AttachFunc(fn AttachFunc[T])
- func (s *GenericStoreImpl[T]) CountBy(ctx context.Context, expr Expression) (int64, error)
- func (s *GenericStoreImpl[T]) Delete(ctx context.Context, id int64) error
- func (s *GenericStoreImpl[T]) DeleteBy(ctx context.Context, expr Ex) (int64, error)
- func (s *GenericStoreImpl[T]) Exists(ctx context.Context, expr Expression) (bool, error)
- func (s *GenericStoreImpl[T]) Find(ctx context.Context, dest T, id int64) error
- func (s *GenericStoreImpl[T]) First(ctx context.Context, expr Expression, order ...OrderedExpression) (T, error)
- func (s *GenericStoreImpl[T]) Get(ctx context.Context, id int64) (T, error)
- func (s *GenericStoreImpl[T]) GetBy(ctx context.Context, expr Expression) (T, error)
- func (s *GenericStoreImpl[T]) GetForUpdate(ctx context.Context, expr Expression, order ...OrderedExpression) (T, error)
- func (s *GenericStoreImpl[T]) Insert(ctx context.Context, req T) error
- func (s *GenericStoreImpl[T]) List(ctx context.Context, opts ...clause.FilterOption) (*response.ListResponse[T], error)
- func (s *GenericStoreImpl[T]) ListBy(ctx context.Context, expr Expression, opts ...clause.FilterOption) (*response.ListResponse[T], error)
- func (s *GenericStoreImpl[T]) ListByEach(ctx context.Context, expr Expression, fn func(item T) error, ...) error
- func (s *GenericStoreImpl[T]) ListByIDs(ctx context.Context, ids []int64) (*response.ListResponse[T], error)
- func (s *GenericStoreImpl[T]) ListEach(ctx context.Context, fn func(item T) error, opts ...clause.FilterOption) error
- func (s *GenericStoreImpl[T]) Update(ctx context.Context, req T) error
- func (s *GenericStoreImpl[T]) UpdateMap(ctx context.Context, id int64, req map[string]any) error
- func (s *GenericStoreImpl[T]) UpdateMapBy(ctx context.Context, req map[string]any, expr Expression) (int64, error)
- func (s *GenericStoreImpl[T]) Upsert(ctx context.Context, req T, target string) (bool, error)
- func (s *GenericStoreImpl[T]) WithTx(conn sql.Executor) *GenericStoreImpl[T]
- type JoinExpression
- type Op
- type OrderedExpression
- type RepoError
- type StoreOption
- func WithExpressions[T model.Modelable](filters ...exp.Expression) StoreOption[T]
- func WithFilters[T model.Modelable](rules ...filter.Rule) StoreOption[T]
- func WithIncludes[T model.Modelable](includes ...string) StoreOption[T]
- func WithJoins[T model.Modelable](joins ...JoinExpression) StoreOption[T]
- func WithPaginatorOptions[T model.Modelable](opts ...paginator.Option) StoreOption[T]
- func WithReturnFields[T model.Modelable](fields ...any) StoreOption[T]
- func WithSelectFields[T model.Modelable](fields ...any) StoreOption[T]
- func WithSortKeys[T model.Modelable](keys ...string) StoreOption[T]
- func WithTablePrefix[T model.Modelable](prefix string) StoreOption[T]
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrBackend = errors.New("repo: backend error") ErrNotFound = errors.New("repo: model not found") ErrDuplicated = errors.New("repo: duplicated model") )
View Source
var ( // T represents a table T = goqu.T // I represent a schema, table, column or any combination separated by "." I = goqu.I // C represents a column C = goqu.C // L represents a literal value L = goqu.L // And represent multiple AND operations together And = goqu.And // Or represent multiple OR operations together Or = goqu.Or // On represent a join condition On = goqu.On )
Functions ¶
func AttachRelation ¶
func NewRepoError ¶
Types ¶
type AttachFunc ¶
type Connection ¶
type Connection struct { Db sql.Database Store sql.Executor // contains filtered or unexported fields }
func NewTestConnection ¶
func NewTestConnection(t *testing.T, withTransaction bool) *Connection
func (*Connection) Close ¶
func (c *Connection) Close(t *testing.T)
type Expression ¶
type Expression = goqu.Expression
type GenericStore ¶
type GenericStore[T model.Modelable] interface { First(ctx context.Context, expr Expression, order ...OrderedExpression) (T, error) Find(ctx context.Context, dest T, id int64) error CountBy(ctx context.Context, expr Expression) (int64, error) Get(ctx context.Context, id int64) (T, error) GetBy(ctx context.Context, expr Expression) (T, error) GetForUpdate(ctx context.Context, expr Expression, order ...OrderedExpression) (T, error) Exists(ctx context.Context, expr Expression) (bool, error) List(ctx context.Context, opts ...clause.FilterOption) (*response.ListResponse[T], error) ListBy(ctx context.Context, expr Expression, opts ...clause.FilterOption) (*response.ListResponse[T], error) ListByIDs(ctx context.Context, ids []int64) (*response.ListResponse[T], error) ListEach(ctx context.Context, fn func(item T) error, opts ...clause.FilterOption) error ListByEach(ctx context.Context, expr Expression, fn func(item T) error, opts ...clause.FilterOption) error Insert(ctx context.Context, req T) error // Upsert inserts a new record in the database, if the target column has a conflict then updates the fields instead Upsert(ctx context.Context, req T, target string) (bool, error) // Update updates a record on the repository Update(ctx context.Context, req T) error // UpdateMap updates a record from the repository, only updates the specified fields in the map UpdateMap(ctx context.Context, id int64, req map[string]any) error // UpdateMapBy updates the records matched by the expression, only updates the specified fields in the map UpdateMapBy(ctx context.Context, req map[string]any, expr Expression) (int64, error) // Delete removes a record from the repository, returns ErrNotFound if the ID doesn't exist Delete(ctx context.Context, id int64) error // DeleteBy removes the records matched by the expression, returns the deleted count on success DeleteBy(ctx context.Context, expr Ex) (int64, error) }
type GenericStoreImpl ¶
type GenericStoreImpl[T model.Modelable] struct { Conn sql.Executor Builder goqu.DialectWrapper Table string // contains filtered or unexported fields }
func NewStore ¶
func NewStore[T model.Modelable](conn sql.Executor, opts ...StoreOption[T]) *GenericStoreImpl[T]
func (*GenericStoreImpl[T]) AttachFunc ¶
func (s *GenericStoreImpl[T]) AttachFunc(fn AttachFunc[T])
func (*GenericStoreImpl[T]) CountBy ¶
func (s *GenericStoreImpl[T]) CountBy(ctx context.Context, expr Expression) (int64, error)
func (*GenericStoreImpl[T]) Delete ¶
func (s *GenericStoreImpl[T]) Delete(ctx context.Context, id int64) error
func (*GenericStoreImpl[T]) Exists ¶
func (s *GenericStoreImpl[T]) Exists(ctx context.Context, expr Expression) (bool, error)
func (*GenericStoreImpl[T]) Find ¶
func (s *GenericStoreImpl[T]) Find(ctx context.Context, dest T, id int64) error
Find returns a record from the database. If no record is found then a ErrNotFound is returned
func (*GenericStoreImpl[T]) First ¶
func (s *GenericStoreImpl[T]) First(ctx context.Context, expr Expression, order ...OrderedExpression) (T, error)
func (*GenericStoreImpl[T]) Get ¶
func (s *GenericStoreImpl[T]) Get(ctx context.Context, id int64) (T, error)
Get returns a record from the database. If no record is found then a ErrNotFound is returned
func (*GenericStoreImpl[T]) GetBy ¶
func (s *GenericStoreImpl[T]) GetBy(ctx context.Context, expr Expression) (T, error)
GetBy returns the first record from the database matching the expression. If no record is found then a ErrNotFound is returned
func (*GenericStoreImpl[T]) GetForUpdate ¶
func (s *GenericStoreImpl[T]) GetForUpdate(ctx context.Context, expr Expression, order ...OrderedExpression) (T, error)
func (*GenericStoreImpl[T]) Insert ¶
func (s *GenericStoreImpl[T]) Insert(ctx context.Context, req T) error
func (*GenericStoreImpl[T]) List ¶
func (s *GenericStoreImpl[T]) List(ctx context.Context, opts ...clause.FilterOption) (*response.ListResponse[T], error)
func (*GenericStoreImpl[T]) ListBy ¶
func (s *GenericStoreImpl[T]) ListBy(ctx context.Context, expr Expression, opts ...clause.FilterOption) (*response.ListResponse[T], error)
func (*GenericStoreImpl[T]) ListByEach ¶
func (s *GenericStoreImpl[T]) ListByEach(ctx context.Context, expr Expression, fn func(item T) error, opts ...clause.FilterOption) error
func (*GenericStoreImpl[T]) ListByIDs ¶
func (s *GenericStoreImpl[T]) ListByIDs(ctx context.Context, ids []int64) (*response.ListResponse[T], error)
func (*GenericStoreImpl[T]) ListEach ¶
func (s *GenericStoreImpl[T]) ListEach(ctx context.Context, fn func(item T) error, opts ...clause.FilterOption) error
func (*GenericStoreImpl[T]) Update ¶
func (s *GenericStoreImpl[T]) Update(ctx context.Context, req T) error
func (*GenericStoreImpl[T]) UpdateMapBy ¶
func (s *GenericStoreImpl[T]) UpdateMapBy(ctx context.Context, req map[string]any, expr Expression) (int64, error)
func (*GenericStoreImpl[T]) WithTx ¶
func (s *GenericStoreImpl[T]) WithTx(conn sql.Executor) *GenericStoreImpl[T]
type JoinExpression ¶
type JoinExpression struct { Expression exp.Expression Condition exp.JoinCondition }
type OrderedExpression ¶
type OrderedExpression = exp.OrderedExpression
type StoreOption ¶
type StoreOption[T model.Modelable] func(c *GenericStoreImpl[T])
func WithExpressions ¶
func WithExpressions[T model.Modelable](filters ...exp.Expression) StoreOption[T]
func WithFilters ¶
func WithFilters[T model.Modelable](rules ...filter.Rule) StoreOption[T]
func WithIncludes ¶
func WithIncludes[T model.Modelable](includes ...string) StoreOption[T]
func WithJoins ¶
func WithJoins[T model.Modelable](joins ...JoinExpression) StoreOption[T]
func WithPaginatorOptions ¶
func WithPaginatorOptions[T model.Modelable](opts ...paginator.Option) StoreOption[T]
func WithReturnFields ¶
func WithReturnFields[T model.Modelable](fields ...any) StoreOption[T]
func WithSelectFields ¶
func WithSelectFields[T model.Modelable](fields ...any) StoreOption[T]
func WithSortKeys ¶
func WithSortKeys[T model.Modelable](keys ...string) StoreOption[T]
func WithTablePrefix ¶
func WithTablePrefix[T model.Modelable](prefix string) StoreOption[T]
Source Files
¶
Click to show internal directories.
Click to hide internal directories.