repository

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDField         QueryField = "id"
	NameField       QueryField = "name"
	RegionField     QueryField = "region"
	TenantIDField   QueryField = "tenant_id"
	ExternalIDField QueryField = "external_id"
	SystemIDField   QueryField = "system_id"
	OwnerIDField    QueryField = "owner_id"
	OwnerTypeField  QueryField = "owner_type"
	CreatedAtField  QueryField = "created_at"
	TypeField       QueryField = "type"
	LabelsField     QueryField = "labels"

	NotEmpty QueryFieldValue = "not_empty"
	Empty    QueryFieldValue = "empty"

	System FieldName = "System"
)
View Source
const (
	DefaultPaginationLimit = 50
)

Variables

View Source
var (
	ErrInvalidPaginationToken = errors.New("token is invalid")
	ErrFailedToEncodeToken    = errors.New("failed to encode token")
	ErrInvalidFieldName       = errors.New("invalid field name in pagination token")
)

Functions

This section is empty.

Types

type CompositeKey

type CompositeKey map[QueryField]any

CompositeKey is a collection of QueryField and matching value that are collectively used to find a record.

func NewCompositeKey

func NewCompositeKey() CompositeKey

NewCompositeKey creates and returns a new CompositeKey.

func (CompositeKey) Where

func (c CompositeKey) Where(q QueryField, v any) CompositeKey

Where adds a condition to the CompositeKey.

type FieldName added in v1.7.0

type FieldName = string

type Join added in v1.7.0

type Join struct {
	Resource Resource
	OnColumn QueryField
	Column   QueryField
}

type PageInfo

type PageInfo struct {
	LastCreatedAt time.Time    `json:"lastCreatedAt"`
	LastKey       CompositeKey `json:"lastKey"`
}

func DecodePageToken

func DecodePageToken(encodedToken string) (*PageInfo, error)

DecodePageToken decodes the token back to a PageInfo struct.

func (PageInfo) Encode

func (p PageInfo) Encode() (string, error)

Encode encodes the PageInfo as a page token.

type Paginator

type Paginator struct {
	PageInfo    *PageInfo
	OrderFields []QueryField
}

Paginator stores the composite key as a single token.

type Query

type Query struct {
	// the Resource type the query is for
	Resource Resource

	// Limit is a max size of returned elements.
	Limit int

	// Paginator handles pagination for list operations if not nil.
	Paginator Paginator

	// OrderFields are the fields used for ordering the results when paginating
	OrderFields []QueryField

	// CompositeKeys  form the where part of the Query
	CompositeKeys []CompositeKey

	// Joins are the resources to be joined with the main resource
	Joins []Join

	// Preloads are the field names to be preloaded with the main resource
	Preloads []FieldName
}

func NewQuery

func NewQuery(resource Resource) *Query

NewQuery creates and returns a new empty query.

func (*Query) ApplyPagination

func (q *Query) ApplyPagination(limit int32, token string) error

ApplyPagination adds pagination parameters if they are provided.

func (*Query) Populate added in v1.7.0

func (q *Query) Populate(fieldNames ...FieldName)

Populate fills the Preloads slice with field names that are needed to fetched with the main resource.

func (*Query) SetLimit

func (q *Query) SetLimit(limit int) *Query

SetLimit sets the limit value for the query.

func (*Query) Where

func (q *Query) Where(compositeKeys ...CompositeKey) *Query

Where adds the given CompositeKey to the query.

type QueryField

type QueryField = string

type QueryFieldValue

type QueryFieldValue = string

type Repository

type Repository interface {
	Create(ctx context.Context, resource Resource) error
	List(ctx context.Context, result any, query Query) error
	Delete(ctx context.Context, resource Resource) (bool, error)
	Find(ctx context.Context, resource Resource) (bool, error)
	Patch(ctx context.Context, resource Resource) (bool, error)
	PatchAll(ctx context.Context, resource Resource, result any, query Query) (int64, error)
	Transaction(ctx context.Context, txFunc TransactionFunc) error
}

Repository defines the interface for Repository operations.

type Resource

type Resource interface {
	TableName() string
	PaginationKey() map[QueryField]any
}

Resource defines the interface for Resource operations.

type TransactionFunc

type TransactionFunc func(context.Context, Repository) error

TransactionFunc is func signature for ExecTransaction.

type UniqueConstraintError

type UniqueConstraintError struct {
	Detail string
}

UniqueConstraintError represents an error caused by a violation of a unique constraint in the database.

func (*UniqueConstraintError) Error

func (u *UniqueConstraintError) Error() string

Error returns an error message describing the unique constraint violation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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