Documentation ¶
Overview ¶
The fields package is responsible for our interactions with struct fields. Its responsibilities are:
- Serializing and deserializing to and from SQL
- Copying to and from values while abstracting away pointer types and nil values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Descriptor ¶
Descriptor is a cache object that holds onto relevant information about our struct field and allows us not to worry about dealing with pointers during the coercion process.
func New ¶
func New(t reflect.Type, tags []string) *Descriptor
New creates a new FieldDescriptor from a type and tags.
func (Descriptor) Scanner ¶
func (d Descriptor) Scanner() *Scanner
Scanner creates a sql.Scanner from the descriptor.
func (Descriptor) ValidateSQLType ¶
func (d Descriptor) ValidateSQLType() error
ValidateSQLType checks to see if the field is a valid SQL value.
type Scanner ¶
type Scanner struct { *Descriptor // contains filtered or unexported fields }
Scanner fulfills the sql.Scanner interface which deserializes SQL values into the type dictated by our descriptor.
func (*Scanner) CopyTo ¶
CopyTo copies the scanner value to another reflect.Value. This is used for setting structs.
type TagSet ¶
type TagSet map[string]struct{}
TagSet holds onto our tags for quick lookup. They are used to hang onto type overrides dictated by structs.
In this example:
type Cat struct { ID int64 `sql:",primary"` LifeStory Blob `sql:",binary,nullable"` }
LifeStory has a TagSet with the following:
TagSet{"binary":{}, "nullable":{}}
type Valuer ¶
type Valuer struct { *Descriptor // contains filtered or unexported fields }
Valuer fulfills the sql/driver.Valuer interface which deserializes our struct field value into a valid SQL value.