pocketbase

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02 15:04:05.000Z"

DateFormat is the ISO date format used for PocketBase date/datetime record fields.

Variables

View Source
var (
	ErrCannotConnect    = errors.New("cannot connect to PocketBase")
	ErrAuthFailed       = errors.New("PocketBase authentication failed")
	ErrUnexpectedStatus = errors.New("unexpected status from PocketBase")
)

Sentinel errors for PocketBase client operations.

View Source
var ErrPocketBaseNotFound = errors.New("pocketbase executable not found in $PATH or ~/.local/bin")

ErrPocketBaseNotFound is returned when the pocketbase binary cannot be located.

View Source
var ErrWaitTimeout = errors.New("timed out waiting for service to be ready")

ErrWaitTimeout is returned when WaitForReady times out.

Functions

func FormatDateLocal

func FormatDateLocal(utcStr string) string

FormatDateLocal parses a PocketBase UTC datetime string and returns it in local time as "YYYY-MM-DD HH:MM". Returns the raw string if parsing fails.

func LqdTasksSchema

func LqdTasksSchema() map[string]any

LqdTasksSchema returns the PocketBase collection schema for lqd_tasks. Go code is the source of truth — not PB migrations.

func StartPocketBase

func StartPocketBase(workDir string) (*exec.Cmd, error)

StartPocketBase starts pocketbase serve as a managed subprocess from workDir. Stdout and stderr are inherited so PocketBase logs appear in the same terminal. The caller is responsible for calling cmd.Process.Kill() on shutdown.

func WaitForReady

func WaitForReady(healthURL string, timeout time.Duration) error

WaitForReady polls healthURL until it returns 200 OK or timeout elapses.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a minimal PocketBase HTTP client.

func NewClient

func NewClient(baseURL, username, password string) (*Client, error)

NewClient authenticates with PocketBase and returns a ready-to-use client.

func NewClientWithToken

func NewClientWithToken(baseURL, token string) *Client

NewClientWithToken returns a client pre-loaded with an existing auth token. Use when a token has already been obtained (e.g. at dashboard startup) to avoid a redundant authentication round-trip.

func (*Client) CollectionExists

func (c *Client) CollectionExists(name string) (bool, error)

CollectionExists checks if a collection exists in PocketBase.

func (*Client) CreateCollection

func (c *Client) CreateCollection(schema map[string]any) error

CreateCollection creates a new collection with the given schema.

func (*Client) CreateRecord

func (c *Client) CreateRecord(collection string, data map[string]any) error

CreateRecord creates a record in the given collection.

func (*Client) DeleteCollection

func (c *Client) DeleteCollection(name string) error

DeleteCollection deletes a collection by name. It first fetches the collection to get its ID.

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(collection, recordID string) error

DeleteRecord deletes a record by ID from the given collection.

func (*Client) FetchRecords

func (c *Client) FetchRecords(collection, filter, sort string, limit ...int) ([]map[string]any, error)

FetchRecords fetches all records from a collection, handling pagination. Optional filter and sort parameters are passed as PB query params. If limit > 0, fetches at most that many records (single page).

func (*Client) Token

func (c *Client) Token() string

Token returns the current authentication token.

func (*Client) UpdateRecord

func (c *Client) UpdateRecord(collection, recordID string, data map[string]any) error

UpdateRecord updates a record by ID in the given collection.

Jump to

Keyboard shortcuts

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