Documentation
¶
Overview ¶
Package lysmeta contains functions that analyze structs.
Index ¶
- func GetInputValue(val any, reflType reflect.Type) (inputVal any)
- func Validate[T any](validate *validator.Validate, input T) (err error)
- type Field
- type Plan
- func (p Plan) DbNames() []string
- func (p Plan) DbValues() (dbNames []string, values []any, err error)
- func (p Plan) Fields() []Field
- func (p Plan) HasValues() bool
- func (p Plan) JsonKeyDbNameMap() map[string]string
- func (p Plan) JsonKeyTypeMap() map[string]reflect.Type
- func (p Plan) JsonKeys() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetInputValue ¶ added in v0.3.28
getInputValue returns val, but contains special handling for lystype date types
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
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
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
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
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
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
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
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
JsonKeyTypeMap returns a map of json keys to their corresponding field types. Fields with json tag "-" are omitted.