lysmeta

package
v0.3.28 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 6 Imported by: 2

README

lysmeta

Functions that analyze structs.

Documentation

Overview

Package lysmeta contains functions that analyze structs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInputValue added in v0.3.28

func GetInputValue(val any, reflType reflect.Type) (inputVal any)

getInputValue returns val, but contains special handling for lystype date types

func Validate

func Validate[T any](validate *validator.Validate, input T) (err error)

Validate uses the validator lib to validate the supplied T returns all errors joined by pipe (|)

Types

type Field added in v0.3.28

type Field struct {
	Name string
	Type reflect.Type

	DbName  string // if db tag is missing or "-", the field is ignored in db operations (unlike pgx, where only "-" is ignored)
	JsonKey string // uses same rules as encoding/json: if json tag is missing or empty, use field name as json key; if json tag is "-", omit field from json

	Value any // only set if the Plan was created with AnalyzeValues
}

Field represents a struct field with db and json metadata, and optionally its value.

type Plan added in v0.3.28

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

Plan represents the metadata of a struct, used for db and json operations. Embedded structs are flattened into the Plan, so the fields slice includes all fields from the struct and its embedded structs. Values are only included if the Plan was created with AnalyzeValues. The Plan is created by Analyze or AnalyzeValues and is immutable thereafter.

func Analyze added in v0.3.28

func Analyze(t any) (plan Plan, err error)

Analyze returns a Plan for the exported fields in struct t, including embedded structs with a db tag. The Plan Field.Value will be nil, and the Plan cached values will be populated for use in getters. It checks for duplicate db names and json keys, and returns an error if any are found.

func AnalyzeValues added in v0.3.28

func AnalyzeValues(t any) (plan Plan, err error)

AnalyzeValues returns a Plan for the exported fields in struct t, including embedded structs with a db tag. The Plan Field.Value will be set to the value from the struct, with special handling for lystype date types.

func (Plan) DbNames added in v0.3.28

func (p Plan) DbNames() []string

DbNames returns the db column names of the fields in the Plan. Fields missing a db tag or with db tag "-" are omitted.

func (Plan) DbValues added in v0.3.28

func (p Plan) DbValues() (dbNames []string, values []any, err error)

DbValues returns slices of db column names and corresponding values, for fields that have a db tag. The Plan must have been created with setValues=true in AnalyzeT.

func (Plan) Fields added in v0.3.28

func (p Plan) Fields() []Field

Fields returns the fields in the Plan, including their metadata and optionally their values if the Plan was created with setValues=true in AnalyzeT.

func (Plan) HasValues added in v0.3.28

func (p Plan) HasValues() bool

HasValues returns true if the Plan was created with setValues=true in AnalyzeT, meaning the Field.Value is populated with values from the struct.

func (Plan) JsonKeyDbNameMap added in v0.3.28

func (p Plan) JsonKeyDbNameMap() map[string]string

JsonKeyDbNameMap returns a map of json keys to their corresponding db column names, for fields that have both json and db tags. Fields with json tag "-" or missing db tag are omitted.

func (Plan) JsonKeyTypeMap added in v0.3.28

func (p Plan) JsonKeyTypeMap() map[string]reflect.Type

JsonKeyTypeMap returns a map of json keys to their corresponding field types. Fields with json tag "-" are omitted.

func (Plan) JsonKeys added in v0.3.28

func (p Plan) JsonKeys() []string

JsonKeys returns the json keys of the fields in the Plan. Fields with json tag "-" are omitted.

Jump to

Keyboard shortcuts

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