fieldtype

package
v0.1.1-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllFieldtype

func GetAllFieldtype() map[string]Definition

GetAllFieldtype get all fieldtype

func IsEmptyInput

func IsEmptyInput(input interface{}) bool

IsEmptyInput returns if it's an empty input. The input can be not string(eg. int - definately not empty)

func Register

func Register(definition Definition)

Register registers a fieldtype

Types

type Definition

type Definition struct {
	Name       string                            //eg. text
	DataType   string                            //eg. string or eg "fieldtype.CustomString"
	Package    string                            //empty if there is no additional package, otherwise it's like 'mycompany.fieldtype'. Used for generating entity's import.
	NewHandler func(definition.FieldDef) Handler //callback to create new handler for this fieldtype
}

Definition includes a fieldtype basic information

func GetFieldtype

func GetFieldtype(fieldtype string) Definition

GetFieldtype return a fieldtype

type EmptyError

type EmptyError struct {
}

Empty Error

func (EmptyError) Error

func (err EmptyError) Error() string

type Event

type Event interface {
	BeforeStore(ctx context.Context, value interface{}, existing interface{}, mode string) (interface{}, error)

	AfterDelete(ctx context.Context, value interface{}) error
}

BeforeSaving is implemented when fieldtype has event before saving and transaction starts.

type Handler

type Handler interface {
	//Load from input, should return the value of BaseType, (eg. int), return error or validation error or empty error
	LoadInput(ctx context.Context, input interface{}, mode string) (interface{}, error)

	//output database field. todo: can support this to generate database field automatically
	DBField() string
}

Fieldtyper is a implementation of a fieldtype, including main logic

func GethHandler

func GethHandler(def definition.FieldDef) Handler

type Outputer

type Outputer interface {
	Output(ctx context.Context, querier querier.Querier, value interface{}) interface{}
}

type RelationParameters

type RelationParameters struct {
	Type      string                 `json:"type"`
	Value     string                 `json:"value"`
	Condition map[string]interface{} `json:"condition"`
}

func ConvertRelationParams

func ConvertRelationParams(params definition.FieldParameters) (RelationParameters, error)

Convert to parameters obj

type StoreHandler

type StoreHandler interface {
	Store(ctx context.Context, value interface{}, contentType string, cid int, transaction *sql.Tx) error
}

type ValidationError

type ValidationError struct {
	Message string
}

func NewValidationError

func NewValidationError(message string) ValidationError

func (ValidationError) Error

func (err ValidationError) Error() string

Validation error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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