Documentation ¶
Index ¶
- func FloatsType() *jsonDataType
- func IntsType() *jsonDataType
- func JSONType(base interface{}) *jsonDataType
- func NoopType() *noopDataType
- func PkgPath(typ reflect.Type) string
- func StringsType() *jsonDataType
- func TimeType() *timeDataType
- type BoolDataType
- type DataType
- type Field
- type FloatDataType
- func (t *FloatDataType) Max(max float64) *FloatDataType
- func (t *FloatDataType) Min(min float64) *FloatDataType
- func (t *FloatDataType) Negative() *FloatDataType
- func (t *FloatDataType) Positive() *FloatDataType
- func (t *FloatDataType) Type() interface{}
- func (t *FloatDataType) Valid(val interface{}) error
- func (t *FloatDataType) Validate(fn func(float64) error) *FloatDataType
- type Formatter
- type FullDataType
- type ImportableDataType
- type IntDataType
- func (t *IntDataType) Max(max int) *IntDataType
- func (t *IntDataType) Min(min int) *IntDataType
- func (t *IntDataType) Negative() *IntDataType
- func (t *IntDataType) Positive() *IntDataType
- func (t *IntDataType) Type() interface{}
- func (t *IntDataType) Valid(val interface{}) error
- func (t *IntDataType) Validate(fn func(int) error) *IntDataType
- type Option
- func DB(name string) Option
- func FieldEdge(configName, edgeName string) Option
- func ForeignKey(configName, fieldName string) Option
- func GraphQL(name string) Option
- func HideFromGraphQL() Option
- func Index() Option
- func Nullable() Option
- func Private() Option
- func ServerDefault(val interface{}) Option
- func Unique() Option
- type PrivateDataType
- type StringDataType
- func (t *StringDataType) DoesNotMatch(r *regexp.Regexp) *StringDataType
- func (t *StringDataType) Format(val interface{}) (interface{}, error)
- func (t *StringDataType) Formatter(fn func(string) string) *StringDataType
- func (t *StringDataType) Length(n int) *StringDataType
- func (t *StringDataType) Match(r *regexp.Regexp) *StringDataType
- func (t *StringDataType) MaxLen(n int) *StringDataType
- func (t *StringDataType) MinLen(n int) *StringDataType
- func (t *StringDataType) NotEmpty() *StringDataType
- func (t *StringDataType) Title() *StringDataType
- func (t *StringDataType) ToLower() *StringDataType
- func (t *StringDataType) ToUpper() *StringDataType
- func (t *StringDataType) TrimSpace() *StringDataType
- func (t *StringDataType) Type() interface{}
- func (t *StringDataType) Valid(val interface{}) error
- func (t *StringDataType) Validate(fn func(string) error) *StringDataType
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FloatsType ¶
func FloatsType() *jsonDataType
FloatsType returns a new Datatype with type []float64. It doesn't enforce that the type saved is of that type without calling EnforceType()
func IntsType ¶
func IntsType() *jsonDataType
IntsType returns a new Datatype with type []int. It doesn't enforce that the type saved is of that type without calling EnforceType()
func JSONType ¶
func JSONType(base interface{}) *jsonDataType
JSONType returns a new DataType where the value is stored in a text column in the db that's json encoded Provides a base type for type enforcement (optional) and to get any package that needs to be included in the generated code
func NoopType ¶
func NoopType() *noopDataType
NoopType returns a type which implemente the DataType interface but doesn't do anything. Shouldn't be used in declaration of fields in GetFields() in an EntConfig. Behavior is undefined
func PkgPath ¶
PkgPath is a recursive function that's called to get the underlying package that should be included to use this type
func StringsType ¶
func StringsType() *jsonDataType
StringsType returns a new Datatype with type []string. It doesn't enforce that the type saved is of that type without calling EnforceType()
func TimeType ¶
func TimeType() *timeDataType
TimeType returns a new DataType with type TimeType Because the default value for time we store in the db is without timezone, we automatically format to UTC To change this, can use Formatter e.g.
field.TimeType().Formatter(func(t time.TimeType) time.TimeType { return t.Local() })
or use a different time format field
Types ¶
type BoolDataType ¶
type BoolDataType struct{}
BoolDataType is the datatype for boolean fields
func (*BoolDataType) Type ¶
func (t *BoolDataType) Type() interface{}
Type returns false to satisfy the DataType interface
type DataType ¶
type DataType interface { // Type method is used to determine the underlying type of the data // that's stored here. Implementors should return the zero-value of the // type stored here. // We currently use static-analysis to infer the type based on what's returned here. Type() interface{} }
DataType interface represents a piece of datum stored in any field in any of the nodes in the graph
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a field that's available on an ent Field exists separate from DataType to store information that's common across different datatypes and to make it easy to add new datatypes that don't have to be bothered with these details. The API here is also good for static analysis, which is the current way the information is parsed and ingested
func F ¶
F takes a datatype and 0 or more options and configures the Field usage is as follows:
func (config *UserConfig) GetFields() ent.FieldMap { return ent.FieldMap { "FirstName": field.F( field.StringType(), ), "EmailAddress": field.F( field.StringType(), field.Unique(), field.DB("email"), ), }, }
type FloatDataType ¶
type FloatDataType struct {
// contains filtered or unexported fields
}
FloatDataType is the datatype for float fields
func FloatType ¶
func FloatType() *FloatDataType
FloatType returns a new DataType with type FloatType
func (*FloatDataType) Max ¶
func (t *FloatDataType) Max(max float64) *FloatDataType
Max validates the maximum value of the float64
func (*FloatDataType) Min ¶
func (t *FloatDataType) Min(min float64) *FloatDataType
Min validates the minimum value of the float64
func (*FloatDataType) Negative ¶
func (t *FloatDataType) Negative() *FloatDataType
Negative validates that the float64 is "negative". Uses a maximum value of 0.0000000001
func (*FloatDataType) Positive ¶
func (t *FloatDataType) Positive() *FloatDataType
Positive validates that the float64 is "positive". Uses a minimum value of 0.0000000001
func (*FloatDataType) Type ¶
func (t *FloatDataType) Type() interface{}
Type returns 0.0 to satisfy the DataType interface
func (*FloatDataType) Valid ¶
func (t *FloatDataType) Valid(val interface{}) error
Valid implements the Validator interface to validate the float64 input
func (*FloatDataType) Validate ¶
func (t *FloatDataType) Validate(fn func(float64) error) *FloatDataType
Validate takes a function that Validates the value of the float64
type Formatter ¶
type Formatter interface {
Format(interface{}) (interface{}, error)
}
Formatter formats the DataType to make sure that it's formatted in the preferred way before storing
type FullDataType ¶
FullDataType represents a DataType that has a Validator and Formatter Not the best name :/
type ImportableDataType ¶
type ImportableDataType interface { DataType // PkgPath returns package that should be imported when this datatype is PkgPath() string }
ImportableDataType interface represents data that need to import a package to be referenced e.g. "time" for time datatype
type IntDataType ¶
type IntDataType struct {
// contains filtered or unexported fields
}
IntDataType is the datatype for int fields
func (*IntDataType) Max ¶
func (t *IntDataType) Max(max int) *IntDataType
Max validates the maximum value of the integer
func (*IntDataType) Min ¶
func (t *IntDataType) Min(min int) *IntDataType
Min validates the minimum value of the integer
func (*IntDataType) Negative ¶
func (t *IntDataType) Negative() *IntDataType
Negative validates that the integer is negative
func (*IntDataType) Positive ¶
func (t *IntDataType) Positive() *IntDataType
Positive validates that the integer is positive
func (*IntDataType) Type ¶
func (t *IntDataType) Type() interface{}
Type returns 0 to satisfy the DataType interface
func (*IntDataType) Valid ¶
func (t *IntDataType) Valid(val interface{}) error
Valid implements the Validator interface to validate the int input
func (*IntDataType) Validate ¶
func (t *IntDataType) Validate(fn func(int) error) *IntDataType
Validate takes a function that Validates the value of the int
type Option ¶
type Option func(*Field)
Option is a function that takes a Field and modifies it in any way. Provides a consistent public API to modify Field as needed
func DB ¶
DB overrides the default name of the column generated for this field in the db Provides a way to change the name of an existing field and keep the underlying db columne the same
func FieldEdge ¶
FieldEdge specifies that this field maps to an edge on a separate Node/edge combo when this field is written to, the corresponding edge is also written to
func ForeignKey ¶
ForeignKey adds a foreignkey index on a separate Node/field combo
func GraphQL ¶
GraphQL overrides the default name of the field generated for GraphQL Provides a way to change the name of an existing field and keep the existing graphQL API the same
func HideFromGraphQL ¶
func HideFromGraphQL() Option
HideFromGraphQL does not expose this Field to GraphQL
func Nullable ¶
func Nullable() Option
Nullable option indicates that a field can be set to nil. Adds NULL to the db and also generates a pointer in the struct
func Private ¶
func Private() Option
Private does not expose this Field outside the package It *also* automatically hides this from GraphQL. It *also* automatically doesn't expose this to actions by default except when an action explicitly includes that field Had to choose a default and we're choosing this default. The assumption is that any field that's private doesn't get default behavior and it's up to the developer to explicitly override this
func ServerDefault ¶
func ServerDefault(val interface{}) Option
ServerDefault sets the default value of a field. This is stored in the DB and should be a static value This is different from Default and UpdateDefault that may be present on some DataTypes and is determined at run time
type PrivateDataType ¶
PrivateDataType indicates that the DataType is private and shouldn't be exposed to graphql, exposed out of the package or by default exposed in actions
type StringDataType ¶
type StringDataType struct {
// contains filtered or unexported fields
}
StringDataType is the datatype for string fields
func StringType ¶
func StringType() *StringDataType
StringType returns a new Datatype with type StringType
func (*StringDataType) DoesNotMatch ¶
func (t *StringDataType) DoesNotMatch(r *regexp.Regexp) *StringDataType
DoesNotMatch ensures that the string does not match a regular expression
func (*StringDataType) Format ¶
func (t *StringDataType) Format(val interface{}) (interface{}, error)
Format implements the Formatter interface to format the string input before storing
func (*StringDataType) Formatter ¶
func (t *StringDataType) Formatter(fn func(string) string) *StringDataType
Formatter takes a function that takes the value of the string and re-formats it The order in which functions are passed in here should not matter ala the associative property in math
func (*StringDataType) Length ¶
func (t *StringDataType) Length(n int) *StringDataType
Length ensures the length of a string is equal to the given number
func (*StringDataType) Match ¶
func (t *StringDataType) Match(r *regexp.Regexp) *StringDataType
Match ensures that the string matches a regular expression
func (*StringDataType) MaxLen ¶
func (t *StringDataType) MaxLen(n int) *StringDataType
MaxLen ensures the max length of a string
func (*StringDataType) MinLen ¶
func (t *StringDataType) MinLen(n int) *StringDataType
MinLen ensures the minimum length of a string
func (*StringDataType) NotEmpty ¶
func (t *StringDataType) NotEmpty() *StringDataType
NotEmpty ensures that the string is not empty
func (*StringDataType) Title ¶
func (t *StringDataType) Title() *StringDataType
Title returns string with all Unicode letters mapped to their Unicode title case.
func (*StringDataType) ToLower ¶
func (t *StringDataType) ToLower() *StringDataType
ToLower returns string with all Unicode letters mapped to their lower case.
func (*StringDataType) ToUpper ¶
func (t *StringDataType) ToUpper() *StringDataType
ToUpper returns string with all Unicode letters mapped to their upper case.
func (*StringDataType) TrimSpace ¶
func (t *StringDataType) TrimSpace() *StringDataType
TrimSpace returns string with all leading and trailing white space removed, as defined by Unicode.
func (*StringDataType) Type ¶
func (t *StringDataType) Type() interface{}
Type returns the empty string to satisfy the DataType interface
func (*StringDataType) Valid ¶
func (t *StringDataType) Valid(val interface{}) error
Valid implements the Validator interface to validate the string input
func (*StringDataType) Validate ¶
func (t *StringDataType) Validate(fn func(string) error) *StringDataType
Validate takes a function that Validates the value of the string