column

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 6 Imported by: 0

README

column GoDoc

The column package is used to extract information about database columns from Go structs.

There is no backward compatibility guarantee for this package.

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 NewIndex

func NewIndex(vals ...int) Index

NewIndex returns an index with the specified values.

func (Index) Append

func (ix Index) Append(index int) Index

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.

func (Index) Clone

func (ix Index) Clone() Index

Clone creates a deep copy of ix.

func (Index) Equal

func (ix Index) Equal(v Index) bool

Equal returns true if ix is equal to v.

func (Index) ValueRO

func (ix Index) ValueRO(v reflect.Value) reflect.Value

ValueRO returns a value from the structure v without checking for nil pointers.

func (Index) ValueRW

func (ix Index) ValueRW(v reflect.Value) reflect.Value

ValueRW returns the value of the field from the structure v. If any referenced field in v contains a nil pointer, then an empty value is created.

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

func ListForType(rowType reflect.Type) []*Info

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 NewPath

func NewPath(fieldName string, fieldTag reflect.StructTag) Path

NewPath returns a new path with a single field.

func (Path) Append

func (path Path) Append(fieldName string, fieldTag reflect.StructTag) Path

Append details of a field to an existing path to create a new path. The original path is unchanged.

func (Path) Clone

func (path Path) Clone() Path

Clone creates a deep copy of path.

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.

func (Path) Equal

func (path Path) Equal(other Path) bool

Equal returns true if path and other are equal.

func (Path) String

func (path Path) String() string

type TagInfo

type TagInfo struct {
	Ignore        bool
	Name          string
	PrimaryKey    bool
	AutoIncrement bool
	Version       bool
	JSON          bool
	NaturalKey    bool
	EmptyNull     bool
}

TagInfo is information obtained about a column from the struct tags of its corresponding field.

func ParseTag

func ParseTag(tag reflect.StructTag) TagInfo

ParseTag returns a TagInfo containing information obtained from the StructTag of the field associated with the column.

Jump to

Keyboard shortcuts

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