Documentation
¶
Index ¶
- Variables
- func And(filters ...string) string
- func Eq(field, value string) string
- func Gt(field, value string) string
- func Gte(field, value string) string
- func Lt(field, value string) string
- func Lte(field, value string) string
- func Neq(field, value string) string
- func Or(filters ...string) string
- type Client
- type ClientOption
- type HTTPError
- type KVStore
- func (s *KVStore) Delete(ctx context.Context, key string) error
- func (s *KVStore) Exists(ctx context.Context, key string) (bool, error)
- func (s *KVStore) Get(ctx context.Context, key string, dest interface{}) error
- func (s *KVStore) List(ctx context.Context, prefix string) ([]string, error)
- func (s *KVStore) Set(ctx context.Context, key string, value interface{}) error
- type ListOptions
- type ListResult
- type Repository
- func (r *Repository[T]) Create(ctx context.Context, record T) (*T, error)
- func (r *Repository[T]) Delete(ctx context.Context, id string) error
- func (r *Repository[T]) Get(ctx context.Context, id string) (*T, error)
- func (r *Repository[T]) List(ctx context.Context, opts ListOptions) (*ListResult[T], error)
- func (r *Repository[T]) Update(ctx context.Context, id string, record T) (*T, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = errors.New("bad request") ErrForbidden = errors.New("forbidden") ErrNotFound = errors.New("not found") ErrConflict = errors.New("conflict") ErrValidation = errors.New("validation failed") ErrRateLimited = errors.New("rate limited") ErrServer = errors.New("server error") )
Sentinel errors returned for common HTTP statuses.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides authenticated HTTP access to PocketBase. It is safe for concurrent use.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures optional Client settings.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient overrides the default http.Client.
func WithLogger ¶
func WithLogger(logger *slog.Logger) ClientOption
WithLogger attaches a logger used for debug information.
func WithRetry ¶
func WithRetry(maxRetries int, backoff time.Duration) ClientOption
WithRetry sets the maximum number of retries for transient errors and the base backoff. Retries apply to network errors and HTTP 429 responses.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the HTTP client timeout.
type KVStore ¶
type KVStore struct {
// contains filtered or unexported fields
}
KVStore offers simple key-value helpers backed by PocketBase.
func NewKVStore ¶
NewKVStore creates a key-value store backed by the provided collection. If collection is empty, a default "kv_store" collection is used.
func (*KVStore) Delete ¶
Delete removes a key. It is idempotent and returns nil if the key does not exist.
type ListOptions ¶
ListOptions describes pagination and filtering options for list calls.
type ListResult ¶
ListResult contains a page of items with pagination metadata.
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
Repository exposes CRUD helpers for PocketBase collections.
func NewRepository ¶
func NewRepository[T any](client *Client, collection string) *Repository[T]
NewRepository creates a repository bound to a PocketBase collection.
func (*Repository[T]) Create ¶
func (r *Repository[T]) Create(ctx context.Context, record T) (*T, error)
Create inserts a new record.
func (*Repository[T]) Delete ¶
func (r *Repository[T]) Delete(ctx context.Context, id string) error
Delete removes a record by ID.
func (*Repository[T]) Get ¶
func (r *Repository[T]) Get(ctx context.Context, id string) (*T, error)
Get fetches a single record by ID.
func (*Repository[T]) List ¶
func (r *Repository[T]) List(ctx context.Context, opts ListOptions) (*ListResult[T], error)
List returns a page of records using the provided options.