storage

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeOffset

func NormalizeOffset(offset int) int

func NormalizePage

func NormalizePage(page int) int

func NormalizePagination

func NormalizePagination(page int, perPage int) (int, int)

func NormalizePerPage

func NormalizePerPage(perPage int) int

func ScanRowsWithScanner

func ScanRowsWithScanner[T any](rows pgx.Rows, scanner func(pgx.Row) (T, error)) ([]T, error)

func ToPgArray

func ToPgArray[T any](slice []T) goqu.Expression

func ToPostgresArray

func ToPostgresArray(value interface{}) []interface{}

Types

type Filter

type Filter struct {
	Rules   []Rule
	OrderBy []Sort
	Limit   int
	Offset  int
}

type Model

type Model interface {
	TableName() string
	GetID() uuid.UUID
	SetID(uuid.UUID)
}

type Oper

type Oper string
const (
	OpEqual              Oper = "="
	OpNotEqual           Oper = "!="
	OpGreaterThan        Oper = ">"
	OpGreaterThanOrEqual Oper = ">="
	OpLessThan           Oper = "<"
	OpLessThanOrEqual    Oper = "<="
	OpLike               Oper = "LIKE"
	OpILike              Oper = "ILIKE"
	OpIn                 Oper = "IN"
	OpNotIn              Oper = "NOT IN"
	OpIsNull             Oper = "IS NULL"
	OpIsNotNull          Oper = "IS NOT NULL"
	OpContains           Oper = "CONTAINS"      // array (@>)
	OpContainedBy        Oper = "CONTAINED_BY"  // array (<@)
	OpOverlaps           Oper = "OVERLAPS"      // array (&&)
	OpJsonContains       Oper = "JSON_CONTAINS" // JSONB (@>)
	OpJsonExists         Oper = "JSON_EXISTS"   // JSONB (?)
)

type PaginationInfo

type PaginationInfo interface {
	GetTotal() int64
	GetPage() int
	GetPerPage() int
	GetTotalPages() int
	GetHasNext() bool
	GetHasPrev() bool
}

type Paginator

type Paginator[T any] struct {
	Items      []T   `json:"items"`
	Total      int64 `json:"total"`
	Page       int   `json:"page"`
	PerPage    int   `json:"perPage"`
	TotalPages int   `json:"totalPages"`
	HasNext    bool  `json:"next"`
	HasPrev    bool  `json:"prev"`
}

func (*Paginator[T]) GetHasNext

func (p *Paginator[T]) GetHasNext() bool

func (*Paginator[T]) GetHasPrev

func (p *Paginator[T]) GetHasPrev() bool

func (*Paginator[T]) GetPage

func (p *Paginator[T]) GetPage() int

func (*Paginator[T]) GetPerPage

func (p *Paginator[T]) GetPerPage() int

func (*Paginator[T]) GetTotal

func (p *Paginator[T]) GetTotal() int64

func (*Paginator[T]) GetTotalPages

func (p *Paginator[T]) GetTotalPages() int

type Querier

type Querier interface {
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
}

type QueryOption

type QueryOption func(*queryConfig)

func WithFilter

func WithFilter(rules ...Rule) QueryOption

func WithLimit

func WithLimit(limit int) QueryOption

func WithLimitOffset

func WithLimitOffset(limit int, offset int) QueryOption

func WithOffset

func WithOffset(offset int) QueryOption

func WithPagination

func WithPagination(page int, perPage int) QueryOption

func WithSort

func WithSort(field string, sort string) QueryOption

func WithSortAsc

func WithSortAsc(field string) QueryOption

func WithSortDesc

func WithSortDesc(field string) QueryOption

type RecordBuilder

type RecordBuilder[T Model] func(T) goqu.Record

type Repository

type Repository[T Model] struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[T Model](
	pool *pgxpool.Pool,
	table string,
	scanner Scanner[T],
	rowsScanner RowsScanner[T],
	recordBuilder RecordBuilder[T],
) *Repository[T]

func (*Repository[T]) Count

func (r *Repository[T]) Count(ctx context.Context, opts ...QueryOption) (int64, error)

func (*Repository[T]) Delete

func (r *Repository[T]) Delete(ctx context.Context, id uuid.UUID) error

func (*Repository[T]) DeleteBatch

func (r *Repository[T]) DeleteBatch(ctx context.Context, ids []uuid.UUID) error

func (*Repository[T]) FindByID

func (r *Repository[T]) FindByID(ctx context.Context, id uuid.UUID) (T, error)

func (*Repository[T]) Insert

func (r *Repository[T]) Insert(ctx context.Context, entity T) (T, error)

func (*Repository[T]) InsertBatch

func (r *Repository[T]) InsertBatch(ctx context.Context, entities []T) error

func (*Repository[T]) List

func (r *Repository[T]) List(ctx context.Context, opts ...QueryOption) ([]T, error)

func (*Repository[T]) One

func (r *Repository[T]) One(ctx context.Context, opts ...QueryOption) (T, error)

func (*Repository[T]) Paginate

func (r *Repository[T]) Paginate(
	ctx context.Context,
	page int,
	perPage int,
	opts ...QueryOption,
) (*Paginator[T], error)

func (*Repository[T]) Update

func (r *Repository[T]) Update(ctx context.Context, entity T) (T, error)

type RowsScanner

type RowsScanner[T Model] func(pgx.Rows) ([]T, error)

type Rule

type Rule struct {
	Field     string
	Operation Oper
	Value     interface{}
}

func NewRule

func NewRule(field string, oper Oper, value interface{}) Rule

type Scanner

type Scanner[T Model] func(pgx.Row) (T, error)

type Sort

type Sort struct {
	Field      string `json:"field"`
	Descending bool   `json:"descending"`
}

Jump to

Keyboard shortcuts

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