reflectp

package
v0.0.0-...-a44c007 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Column string

	// Whether this field is read-only, meaning it should not be used for inserts/updatesbe scanned into.
	ReadOnly bool
	// Full field index to this field from our root struct
	Index []int
	// Direct type of field, equal to Type unless pointer
	DirectType reflect.Type
	// Type of field, may be a pointer.
	Type reflect.Type
	// contains filtered or unexported fields
}

Field represents a Field in a struct. Adapted from json package reflection. Key difference is json recursively encodes/decodes, we're handling flat tabular data.

func (*Field) Fields

func (f *Field) Fields() *Fields

Get the sub fields of this field when it's a struct itself.

func (*Field) IsEmbeddedStruct

func (f *Field) IsEmbeddedStruct() bool

type Fields

type Fields struct {
	ByColumnName map[string]*Field
	Type         reflect.Type
}

Fields represents the fields of a struct.

func FieldsFactory

func FieldsFactory(t reflect.Type) (*Fields, error)

Internally, all types are stored in a cache to avoid repeated work.

func (*Fields) IsEmbeddedStruct

func (f *Fields) IsEmbeddedStruct() bool

func (*Fields) Rows

func (f *Fields) Rows(rows *sql.Rows) (*FieldsRows, error)

func (*Fields) Writable

func (f *Fields) Writable() map[string]*Field

WriteFields returns the fields that can be written to (ie. are actual columns in table). This is based on struct tags and heuristics around anonymous embeds.

type FieldsRows

type FieldsRows struct {
	*sql.Rows
	// contains filtered or unexported fields
}

FieldsRows handles scanning rows into given struct field.

func NewFieldsRows

func NewFieldsRows(f *Fields, rows *sql.Rows) (*FieldsRows, error)

func (*FieldsRows) Scan

func (sr *FieldsRows) Scan(_val ...reflect.Value) (reflect.Value, error)

Scan a row into reflected value. Will automatically setup a new value if needed

Jump to

Keyboard shortcuts

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