repository

package
v1.0.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RETURNING_ID = "RETURNING id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IRepository

type IRepository interface {
	Create(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
	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 Related interface {
	GetParentID() int64
	PushToParent(parent any)
}

type Relation

type Relation[R any] struct {
	ForeignKey     string
	Repo           Repository[R]
	ParentIdGetter func(R) int64
}

func WrapRelation

func WrapRelation[R any](r Relation[R]) Relation[any]

func (Relation[R]) GetForeignKey

func (r Relation[R]) GetForeignKey() string

func (Relation[R]) GetParentId

func (r Relation[R]) GetParentId(child R) int64

type Repository

type Repository[T any] struct {
	DB            pg_api.PgDbClient
	InsertBuilder sq.InsertBuilder
	SelectBuilder sq.SelectBuilder
	UpdateBuilder sq.UpdateBuilder
	DeleteBuilder sq.DeleteBuilder
	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 pg.DbClient,
	insertBuilder sq.InsertBuilder,
	selectBuilder sq.SelectBuilder,
	updateBuilder sq.UpdateBuilder,
	deleteBuilder sq.DeleteBuilder,
	converter func(row pgx.Row) any) 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]) Delete

func (repo Repository[T]) Delete(ctx context.Context, id int64) 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]) GetById

func (repo Repository[T]) GetById(ctx context.Context, id int64) T

func (Repository[T]) Update

func (repo Repository[T]) Update(ctx context.Context, fields map[string]interface{}, id int64) int64

func (Repository[T]) UpdateCollection

func (repo Repository[T]) UpdateCollection(ctx context.Context, fields map[string]interface{}, where sq.Sqlizer) int64

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL