Documentation
¶
Overview ¶
Package column extracts database column information from Go struct fields.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index []int
Index is used to efficiently find the value for a database column in the associated field within a structure. In most cases an index is a single integer, which represents the index of the relevant field in the structure. In the case of fields in embedded structs, a field index consists of more than one integer.
func (Index) Append ¶
Append a number to an existing index to create a new index. The original index ix is unchanged.
If ix is nil, then Append returns an index with a single index value.
type Info ¶
type Info struct { Field reflect.StructField Index Index Path Path FieldNames string // one or more field names, joined by periods Tag TagInfo // meta data from the struct field tag }
Info contains information about a database column that has been extracted from a struct field using reflection.
func ListForType ¶
ListForType returns a list of column information associated with the specified type, which must be a struct.
type NamingConvention ¶
type NamingConvention interface { // Convert accepts the name of a Go struct field, and returns // the equivalent name for the field according to the naming convention. Convert(fieldName string) string // Join joins two or more string fragments to form a column name. // This method is used for naming columns based on fields within embedded // structures. The column name will be based on the name of // the Go struct field and its enclosing embedded struct fields. Join(frags []string) string }
NamingConvention provides naming convention methods for inferring database column names from Go struct field names.
type Path ¶
type Path []struct { // FieldName is the name of the associated StructField. FieldName string // FieldTag is the tag of the associated StructField. FieldTag reflect.StructTag }
A Path contains information about all the StructFields traversed to obtain the value for a column.
The significance of the path is that it is used to construct the column name, either by the column name(s) specified in the struct tags, or by applying a naming convention to the field name(s).
func (Path) Append ¶
Append details of a field to an existing path to create a new path. The original path is unchanged.
func (Path) ColumnName ¶
func (path Path) ColumnName(nc NamingConvention, key string) string
ColumnName returns a column name by applying the naming convention to the contents of the path.