fields

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 8 Imported by: 0

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

type Descriptor struct {
	Tags TagSet
	Type reflect.Type
	Kind reflect.Kind
	Ptr  bool
}

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.

func (*Descriptor) Valuer

func (d *Descriptor) Valuer(val reflect.Value) Valuer

Valuer creates a sql/driver.Valuer from the type and 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) Scan

func (s *Scanner) Scan(src interface{}) error

Scan satisfies the sql.Scanner interface. The src value will be one of the following:

int64
float64
bool
[]byte
string
time.Time
nil - for NULL values

func (*Scanner) Target

func (s *Scanner) Target(value reflect.Value)

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":{}}

func (TagSet) Contains

func (t TagSet) Contains(tag string) bool

Contains returns true if the set contains the tag.

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.

func (Valuer) Value

func (f Valuer) Value() (driver.Value, error)

Value satisfies the sql/driver.Valuer interface. The value should be one of the following:

int64
float64
bool
[]byte
string
time.Time
nil - for NULL values

Jump to

Keyboard shortcuts

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