Documentation
¶
Index ¶
Constants ¶
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" )
const (
DefaultPaginationLimit = 50
)
Variables ¶
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 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 ¶
DecodePageToken decodes the token back to a PageInfo struct.
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 (*Query) ApplyPagination ¶
ApplyPagination adds pagination parameters if they are provided.
func (*Query) Populate ¶ added in v1.7.0
Populate fills the Preloads slice with field names that are needed to fetched with the main resource.
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.