Documentation
¶
Index ¶
- Constants
- type Closer
- type DbApi
- type DbClient
- type IRepository
- type Identifiable
- type Pinger
- type Related
- type Relation
- type Repository
- func (repo Repository[T]) Create(ctx context.Context, values ...interface{}) int64
- func (repo Repository[T]) Delete(ctx context.Context, id int64) int64
- func (repo Repository[T]) GetAll(ctx context.Context) []T
- func (repo Repository[T]) GetBy(ctx context.Context, where sq.Sqlizer) []T
- func (repo Repository[T]) GetByBuilder(ctx context.Context, selectBuilder sq.SelectBuilder) []T
- func (repo Repository[T]) GetById(ctx context.Context, id int64) T
- func (repo Repository[T]) Update(ctx context.Context, fields map[string]interface{}, id int64) int64
- func (repo Repository[T]) UpdateCollection(ctx context.Context, fields map[string]interface{}, where sq.Sqlizer) int64
- func (repo Repository[T]) UpdateReturning(ctx context.Context, builder sq.UpdateBuilder) any
- func (repo Repository[T]) UpdateReturningWithExtendedConverter(ctx context.Context, builder sq.UpdateBuilder, ...) any
- func (repo Repository[T]) Upsert(ctx context.Context, values ...interface{}) int64
Constants ¶
View Source
const (
RETURNING_ID = "RETURNING id"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DbApi ¶
type DbApi interface {
pg_api.SQLExecutor
pg_api.Transactor
Pinger
Closer
}
type IRepository ¶
type IRepository interface {
Create(ctx context.Context, values ...interface{}) int64
Upsert(ctx context.Context, values ...interface{}) int64
GetById(ctx context.Context, id int64) any
GetAll(ctx context.Context) []any
GetBy(ctx context.Context, where sq.Sqlizer) []any
GetByBuilder(ctx context.Context, selectBuilder sq.SelectBuilder) []any
Delete(ctx context.Context, id int64) int64
UpdateCollection(ctx context.Context, fields map[string]interface{}, where sq.Sqlizer) int64
Update(ctx context.Context, fields map[string]interface{}, id int64) int64
UpdateReturning(ctx context.Context, builder sq.UpdateBuilder, entityConverter func(row pgx.Row) any) any
}
type Identifiable ¶
type Identifiable interface {
GetID() int64
}
type Relation ¶
type Relation[R any] struct { ForeignKey string Repo Repository[R] ParentIdGetter func(R) int64 }
func (Relation[R]) GetForeignKey ¶
func (Relation[R]) GetParentId ¶
type Repository ¶
type Repository[T any] struct { DB DbClient InsertBuilder sq.InsertBuilder SelectBuilder sq.SelectBuilder UpdateBuilder sq.UpdateBuilder DeleteBuilder sq.DeleteBuilder UpsertBuilder sq.InsertBuilder ExtraBuilders []builder.Builder Converter func(row pgx.Row) any // type is any to allow generalization Relations []Relation[any] // the relation type is any because it really any entity AddRelated func(*T, any) AddRelation func(Relation[any]) // contains filtered or unexported fields }
func NewRepository ¶
func NewRepository[T any]( anchor T, db DbClient, insertBuilder sq.InsertBuilder, selectBuilder sq.SelectBuilder, updateBuilder sq.UpdateBuilder, deleteBuilder sq.DeleteBuilder, upsertBuilder sq.InsertBuilder, extraBuilders []builder.Builder, converter func(row pgx.Row) *T) Repository[T]
func WrapRepository ¶
func WrapRepository[R any](repo Repository[R]) Repository[any]
func (Repository[T]) Create ¶
func (repo Repository[T]) Create(ctx context.Context, values ...interface{}) int64
func (Repository[T]) GetAll ¶
func (repo Repository[T]) GetAll(ctx context.Context) []T
func (Repository[T]) GetBy ¶
func (repo Repository[T]) GetBy(ctx context.Context, where sq.Sqlizer) []T
func (Repository[T]) GetByBuilder ¶ added in v1.0.68
func (repo Repository[T]) GetByBuilder(ctx context.Context, selectBuilder sq.SelectBuilder) []T
func (Repository[T]) UpdateCollection ¶
func (Repository[T]) UpdateReturning ¶
func (repo Repository[T]) UpdateReturning(ctx context.Context, builder sq.UpdateBuilder) any
func (Repository[T]) UpdateReturningWithExtendedConverter ¶
func (repo Repository[T]) UpdateReturningWithExtendedConverter(ctx context.Context, builder sq.UpdateBuilder, entityConverter func(row pgx.Row) any) any
Click to show internal directories.
Click to hide internal directories.