column

package
v0.0.0-...-9522951 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 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
	PrimaryKey    bool
	AutoIncrement bool
	Version       bool
	JSON          bool
	EmptyNull     bool
}

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 Path

type Path []struct {
	// FieldName is the name of the associated StructField.
	FieldName string

	// ColumnName is the associated column name, extracted
	// from the StructTag. If no column name has been specified,
	// this field is blank.
	ColumnName string
}

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, columnName string) Path

NewPath returns a new path with a single field.

func (Path) Append

func (path Path) Append(fieldName, columnName string) 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) 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
}

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