field

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(name string) *boolBuilder

Bool returns a new Field with type bool.

func Bytes

func Bytes(name string) *bytesBuilder

Bytes returns a new Field with type bytes/buffer. In MySQL and SQLite, it is the "BLOB" type, and it does not support for Gremlin.

func Enum

func Enum(name string) *enumBuilder

Enum returns a new Field with type enum. An example for defining enum is as follows:

field.Enum("state").
	Values(
		"on",
		"off",
	).
	Default("on")

func Float

func Float(name string) *float64Builder

Float returns a new Field with type float64.

func Float32

func Float32(name string) *float32Builder

Float32 returns a new Field with type float32.

func Floats

func Floats(name string) *jsonBuilder

Floats returns a new JSON Field with type []float.

func Int

func Int(name string) *intBuilder

Int returns a new Field with type int.

func Int16

func Int16(name string) *int16Builder

Int16 returns a new Field with type int16.

func Int32

func Int32(name string) *int32Builder

Int32 returns a new Field with type int32.

func Int64

func Int64(name string) *int64Builder

Int64 returns a new Field with type int64.

func Int8

func Int8(name string) *int8Builder

Int8 returns a new Field with type int8.

func Ints

func Ints(name string) *jsonBuilder

Ints returns a new JSON Field with type []int.

func JSON

func JSON(name string, typ interface{}) *jsonBuilder

JSON returns a new Field with type json that is serialized to the given object. For example:

field.JSON("dirs", []http.Dir{}).
	Optional()

field.JSON("info", &Info{}).
	Optional()

func String

func String(name string) *stringBuilder

String returns a new Field with type string.

func Strings

func Strings(name string) *jsonBuilder

Strings returns a new JSON Field with type []string.

func Text

func Text(name string) *stringBuilder

Text returns a new string field without limitation on the size. In MySQL, it is the "longtext" type, but in SQLite and Gremlin it has not effect.

func Time

func Time(name string) *timeBuilder

Time returns a new Field with type timestamp.

func UUID

func UUID(name string, typ driver.Valuer) *uuidBuilder

UUID returns a new Field with type UUID. An example for defining UUID field is as follows:

field.UUID("id", uuid.New())

func Uint

func Uint(name string) *uintBuilder

Uint returns a new Field with type uint.

func Uint16

func Uint16(name string) *uint16Builder

Uint16 returns a new Field with type uint16.

func Uint32

func Uint32(name string) *uint32Builder

Uint32 returns a new Field with type uint32.

func Uint64

func Uint64(name string) *uint64Builder

Uint64 returns a new Field with type uint64.

func Uint8

func Uint8(name string) *uint8Builder

Uint8 returns a new Field with type uint8.

Types

type Annotation added in v0.3.0

type Annotation interface {
	// Name defines the name of the annotation to be retrieved by the codegen.
	Name() string
}

Annotation is used to attach arbitrary metadata to the field object in codegen. The object must be serializable to JSON raw value (e.g. struct, map or slice). Template extensions can retrieve this metadata and use it inside their templates.

type Descriptor

type Descriptor struct {
	Tag           string            // struct tag.
	Size          int               // varchar size.
	Name          string            // field name.
	Info          *TypeInfo         // field type info.
	Unique        bool              // unique index of field.
	Nillable      bool              // nillable struct field.
	Optional      bool              // nullable field in database.
	Immutable     bool              // create-only field.
	Default       interface{}       // default value on create.
	UpdateDefault interface{}       // default value on update.
	Validators    []interface{}     // validator functions.
	StorageKey    string            // sql column or gremlin property.
	Enums         map[string]string // enum values.
	Sensitive     bool              // sensitive info string field.
	SchemaType    map[string]string // override the schema type.
	Annotations   []Annotation      // field annotations.
	// contains filtered or unexported fields
}

A Descriptor for field configuration.

func (*Descriptor) Err added in v0.2.2

func (d *Descriptor) Err() error

Err returns the error, if any, that was added by the field builder.

type EnumValues added in v0.3.0

type EnumValues interface {
	Values() []string
}

EnumValues defines the interface for getting the enum values.

type RType added in v0.2.3

type RType struct {
	Name    string
	Kind    reflect.Kind
	PkgPath string
	Methods map[string]struct{ In, Out []*RType }
}

RType holds a serializable reflect.Type information of Go object. Used by the entc package.

func (*RType) TypeEqual added in v0.2.3

func (r *RType) TypeEqual(t reflect.Type) bool

TypeEqual tests if the RType is equal to given reflect.Type.

type Type

type Type uint8

A Type represents a field type.

const (
	TypeInvalid Type = iota
	TypeBool
	TypeTime
	TypeJSON
	TypeUUID
	TypeBytes
	TypeEnum
	TypeString
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt
	TypeInt64
	TypeUint8
	TypeUint16
	TypeUint32
	TypeUint
	TypeUint64
	TypeFloat32
	TypeFloat64
)

List of field types.

func (Type) ConstName

func (t Type) ConstName() string

ConstName returns the constant name of a info type. It's used by entc for printing the constant name in templates.

func (Type) Numeric

func (t Type) Numeric() bool

Numeric reports if the given type is a numeric type.

func (Type) String

func (t Type) String() string

String returns the string representation of a type.

func (Type) Valid

func (t Type) Valid() bool

Valid reports if the given type if known type.

type TypeInfo

type TypeInfo struct {
	Type     Type
	Ident    string
	PkgPath  string
	Nillable bool // slices or pointers.
	RType    *RType
}

TypeInfo holds the information regarding field type. Used by complex types like JSON and Bytes.

func (TypeInfo) Comparable added in v0.2.6

func (t TypeInfo) Comparable() bool

Comparable reports whether values of this type are comparable.

func (TypeInfo) ConstName

func (t TypeInfo) ConstName() string

ConstName returns the const name of the info type.

func (TypeInfo) Numeric

func (t TypeInfo) Numeric() bool

Numeric reports if the given type is a numeric type.

func (TypeInfo) String

func (t TypeInfo) String() string

String returns the string representation of a type.

func (TypeInfo) Stringer added in v0.2.3

func (t TypeInfo) Stringer() bool

Stringer indicates if this type implements the Stringer interface.

func (TypeInfo) Valid

func (t TypeInfo) Valid() bool

Valid reports if the given type if known type.

func (TypeInfo) ValueScanner added in v0.2.3

func (t TypeInfo) ValueScanner() bool

ValueScanner indicates if this type implements the ValueScanner interface.

type ValueScanner added in v0.2.3

type ValueScanner interface {
	driver.Valuer
	sql.Scanner
}

ValueScanner is the interface that groups the Value and the Scan methods.

Directories

Path Synopsis
gen is a codegen cmd for generating numeric build types from template.
gen is a codegen cmd for generating numeric build types from template.

Jump to

Keyboard shortcuts

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