repository

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparable

type Comparable uint8

Comparable represents a comparison operator for filtering.

const (
	// Eq is the equality operator '='.
	Eq Comparable = iota

	// Neq is the inequality operator '!='.
	Neq

	// Gt is the greater than operator '>'.
	Gt

	// Gte is the greater than or equal operator '>='.
	Gte

	// Lt is the less than operator '<'.
	Lt

	// Lte is the less than or equal operator '<='.
	Lte

	// LIKE is the pattern matching operator 'LIKE'.
	// Use with '%' wildcards in the value.
	LIKE

	// IN is the membership operator 'IN(...)'.
	// The value should contain comma-separated values.
	IN
)

Comparable defines comparison operators for filtering database queries. Each constant represents a standard SQL operator.

func (Comparable) String

func (i Comparable) String() string

type Counter

type Counter interface {
	// Count returns the total number of items matching the filters.
	// This is typically used to calculate the total number of pages
	// when implementing pagination.
	//
	// Parameters:
	//   - ctx: context for cancellation and timeouts
	//   - filters: filtering criteria (may be empty)
	//
	// Returns:
	//   - int: total count of matching items
	//   - error: any error encountered during the query
	Count(ctx context.Context, filters ...*Filter) (int, error)
}

Counter defines the interface for counting items matching given filters.

type Filter

type Filter struct {
	// ColumnName is the name of the database column to filter on.
	ColumnName string

	// Value is the value to compare against (as string, will be converted by the driver).
	Value string

	// Comparable is the comparison operator (Eq, Neq, Gt, Gte, Lt, Lte, LIKE, IN).
	Comparable Comparable
}

Filter represents filtering criteria for database queries. It defines a condition on a specific column with a value and comparison operator.

func NewFilter

func NewFilter(columnName string, value string, comparable Comparable) *Filter

NewFilter creates a new Filter instance with the given column, value, and operator. Example:

filter := NewFilter("age", "25", Gte)  // age >= 25

type Page

type Page struct {
	// Number is the page number (starting from 1).
	Number uint64

	// Limit is the maximum number of items per page.
	Limit uint32
}

Page represents pagination parameters for database queries. It defines which subset of results to return and how many items per page.

func NewPage

func NewPage(number uint64, limit uint32) *Page

NewPage creates a new Page instance with the given number and limit. Example:

page := NewPage(1, 20)  // first page, 20 items per page

type Pager

type Pager[T any] interface {
	// Page returns a paginated list of items.
	// Parameters:
	//   - ctx: context for cancellation and timeouts
	//   - page: pagination parameters (page number and limit)
	//   - sorts: sorting criteria (may be empty)
	//   - filters: filtering criteria (may be empty)
	//
	// Returns:
	//   - []T: slice of items for the current page
	//   - error: any error encountered during the query
	Page(ctx context.Context, page *Page, sorts []*Sort, filters ...*Filter) ([]T, error)
}

Pager defines the interface for paginated data retrieval. It returns a slice of items for the requested page, applying sorting and filters.

type Repository

type Repository[T any] interface {
	Pager[T]
	Counter
}

Repository combines pagination and counting capabilities for a specific entity type. It provides a standard interface for data access operations that can be implemented by different database drivers (PostgreSQL, MySQL, etc.).

Example:

type UserRepository interface {
    repository.Repository[User]
    FindByEmail(ctx context.Context, email string) (*User, error)
}

type Sort

type Sort struct {
	// ColumnName is the name of the database column to sort by.
	ColumnName string

	// Direction is the sort direction (ASC or DESC).
	Direction SortDirection
}

Sort represents sorting criteria for database queries.

func NewSort

func NewSort(columnName string, direction SortDirection) *Sort

NewSort creates a new Sort instance with the given column and direction. Example:

sort := NewSort("created_at", DESC)

type SortDirection

type SortDirection uint8

SortDirection represents the sorting direction (ASC or DESC).

const (
	// ASC indicates ascending order (A to Z, smallest to largest).
	ASC SortDirection = iota

	// DESC indicates descending order (Z to A, largest to smallest).
	DESC
)

SortDirection defines the order of sorting for query results.

func (SortDirection) String

func (i SortDirection) String() string

Jump to

Keyboard shortcuts

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