client

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPaging added in v1.0.7

func ApplyPaging[T any](items []*T, paging query.Paging) []*T

func FilterExpressionAsPredicate added in v1.0.7

func FilterExpressionAsPredicate[T any](fe query.FilterExpression, item *T) bool

func InExpressionAsPredicate added in v1.0.7

func InExpressionAsPredicate[T any](ie query.InExpression, item *T) bool

func JunctionExpressionPredicate added in v1.0.7

func JunctionExpressionPredicate[T any](je query.JunctionExpression, item *T) bool

func LoadAll added in v1.0.7

func LoadAll[T any](ctx context.Context, c GenericInterface[T], fe query.FilterExpression, orders ...query.Order) ([]*T, error)

func LoadAllInBatch added in v1.0.7

func LoadAllInBatch[T any](ctx context.Context, c GenericInterface[T], fe query.FilterExpression, batchSize int, orders ...query.Order) ([]*T, error)

func LoadAllInBatchWithCap added in v1.0.8

func LoadAllInBatchWithCap[T any](ctx context.Context, c GenericInterface[T], fe query.FilterExpression, batchSize int, cap int, orders ...query.Order) ([]*T, error)

func NewApi added in v1.0.8

func NewApi(endpoint string, opts ...api.ClientOption) (api.ClientWithResponsesInterface, error)

func NotExpressionAsPredicate added in v1.0.7

func NotExpressionAsPredicate[T any](ne query.NotExpression, item *T) bool

func SimpleExpressionPredicate added in v1.0.7

func SimpleExpressionPredicate[T any](se query.SimpleExpression, item *T) bool

Types

type DecoderFn

type DecoderFn[T any] func(dto api.UntypedDto) (*T, error)

type EncoderFn

type EncoderFn[T any] func(*T) (api.UntypedDto, error)

type GenericInterface

type GenericInterface[T any] interface {
	// Api get access to generated OpenAPI interface
	Api() api.ClientWithResponsesInterface
	// Raw gets access to untyped API
	Raw() RawInterface
	Create(context.Context, *T) (*T, error)
	Get(context.Context, string) (*T, error)
	List(context.Context, query.Interface) ([]*T, int, error)
	Update(context.Context, string, *T) (*T, error)
	// Delete removes single entity instance by its ID
	Delete(context.Context, string) error
	BulkUpdate(context.Context, []*T, api.BulkUpdateMode) error
	Query(context.Context, string, query.Interface, []string) ([]*T, int, error)
}

func New

func New[T any](endpoint, backend, entity string, opts ...Opt[T]) (GenericInterface[T], error)

func NewInMemory added in v1.0.7

func NewInMemory[T any](isKeyFn func(string, *T) bool, initData []*T) GenericInterface[T]

type GenericOpt added in v1.0.8

type GenericOpt[T any] func(*generic[T])

type Opt

type Opt[T any] func(*generic[T])

func IdProperty added in v1.0.7

func IdProperty[T any](prop string) Opt[T]

IdProperty can override default ID property ("id")

func ReadOnlyProperties added in v1.0.7

func ReadOnlyProperties[T any](props []string) Opt[T]

ReadOnlyProperties sets properties that will not be sent to REST API during create/update operations. Such properties might be generated by backend itself, ie auto_increment columns or timestamps.

func WithClientOptions

func WithClientOptions[T any](copts ...api.ClientOption) Opt[T]

func WithLogger

func WithLogger[T any](l *slog.Logger) Opt[T]

func WithPayloadDecoder

func WithPayloadDecoder[T any](decFn DecoderFn[T]) Opt[T]

func WithPayloadEncoder

func WithPayloadEncoder[T any](encFn EncoderFn[T]) Opt[T]

type RawInterface added in v1.0.7

type RawInterface interface {
	// Create creates new entity instance
	Create(context.Context, api.UntypedDto) (*api.UntypedDto, error)
	// Get gets single entity instance by its ID
	Get(context.Context, string) (*api.UntypedDto, error)
	// List lists entity instances based on provided query
	List(context.Context, query.Interface) (*api.PagedResult, error)
	// Update updates single entity identified by its key with values provided as map.
	// This method exists to address limitation of generic API to perform updates by i.e. skipping empty strings.
	Update(context.Context, string, api.UntypedDto) (*api.UntypedDto, error)
	// BulkUpdate perform multiple mutation operations in one transaction
	BulkUpdate(context.Context, []api.UntypedDto, api.BulkUpdateMode) error
	// Query executes named query already defined in server-side configuration and returns result.
	Query(context.Context, string, query.Interface, []string) (*api.PagedResult, error)
}

type RawOpt added in v1.0.8

type RawOpt func(*rawImpl)

Jump to

Keyboard shortcuts

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