computedfields

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 4 Imported by: 0

README

Computed fields registry for pocketbase

This very minor abstraction exists for two purposes:

  1. Computed fields all live in one place
  2. Additional fields can be tied into typescript generation (package github.com/davenh99/pb-typescript)

Example of adding computed fields to typescript output:

gentypes.Register(app, gentypes.Config{
    FilePath:                   "ui",
    CollectionAdditionalFields: c.ComputedFieldsCfg.ExtractFields(),
    PrintSelectOptions:         true,
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(app *pocketbase.PocketBase, cfg Config)

Types

type ComputedField

type ComputedField struct {
	FieldName string
	FieldType FieldType
	// Compute needs to return the field value
	Compute func(e *core.RecordEnrichEvent) any
}

FieldType should be any of text, number, bool, json

type Config

type Config struct {
	CollectionComputedFields map[string][]ComputedField
}

func (*Config) ExtractFields

func (c *Config) ExtractFields() map[string][]gentypes.AdditionalField

type Field

type Field struct {
	FieldName string
	FieldType string
	ReadOnly  bool
}

func (Field) GetName

func (f Field) GetName() string

func (Field) GetType

func (f Field) GetType() string

func (Field) IsReadOnly

func (f Field) IsReadOnly() bool

type FieldType

type FieldType string
const (
	TEXT   FieldType = "text"
	NUMBER FieldType = "number"
	BOOL   FieldType = "bool"
	JSON   FieldType = "json"
)

Jump to

Keyboard shortcuts

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