package field
import "entgo.io/ent/schema/field"
Index ¶
- func Any(name string) *jsonBuilder
- func Bool(name string) *boolBuilder
- func Bytes(name string) *bytesBuilder
- func Enum(name string) *enumBuilder
- func Float(name string) *float64Builder
- func Float32(name string) *float32Builder
- func Floats(name string) *sliceBuilder[float64]
- func Int(name string) *intBuilder
- func Int16(name string) *int16Builder
- func Int32(name string) *int32Builder
- func Int64(name string) *int64Builder
- func Int8(name string) *int8Builder
- func Ints(name string) *sliceBuilder[int]
- func JSON(name string, typ any) *jsonBuilder
- func Other(name string, typ driver.Valuer) *otherBuilder
- func String(name string) *stringBuilder
- func Strings(name string) *sliceBuilder[string]
- func Text(name string) *stringBuilder
- func Time(name string) *timeBuilder
- func UUID(name string, typ driver.Valuer) *uuidBuilder
- func Uint(name string) *uintBuilder
- func Uint16(name string) *uint16Builder
- func Uint32(name string) *uint32Builder
- func Uint64(name string) *uint64Builder
- func Uint8(name string) *uint8Builder
- type Annotation
- func ID(first, second string, fields ...string) *Annotation
- func (a Annotation) Merge(other schema.Annotation) schema.Annotation
- func (Annotation) Name() string
- type BinaryValueScanner
- func (BinaryValueScanner[T]) FromValue(v driver.Value) (tv T, err error)
- func (BinaryValueScanner[T]) ScanValue() ValueScanner
- func (BinaryValueScanner[T]) Value(v T) (driver.Value, error)
- type Descriptor
- type EnumValues
- type RType
- func (r *RType) Implements(typ reflect.Type) bool
- func (r *RType) IsPtr() bool
- func (r *RType) String() string
- func (r *RType) TypeEqual(t reflect.Type) bool
- type TextValueScanner
- func (TextValueScanner[T]) FromValue(v driver.Value) (tv T, err error)
- func (TextValueScanner[T]) ScanValue() ValueScanner
- func (TextValueScanner[T]) Value(v T) (driver.Value, error)
- type Type
- func (t Type) ConstName() string
- func (t Type) Float() bool
- func (t Type) Integer() bool
- func (t Type) Numeric() bool
- func (t Type) String() string
- func (t Type) Valid() bool
- type TypeInfo
- func (t TypeInfo) Comparable() bool
- func (t TypeInfo) ConstName() string
- func (t TypeInfo) Numeric() bool
- func (t TypeInfo) String() string
- func (t TypeInfo) Stringer() bool
- func (t TypeInfo) Valid() bool
- func (t TypeInfo) Validator() bool
- func (t TypeInfo) ValueScanner() bool
- func (t TypeInfo) Valuer() bool
- type TypeValueScanner
- type Validator
- type ValueScanner
- type ValueScannerFunc
Functions ¶
func Any ¶
func Any(name string) *jsonBuilder
Any returns a new JSON Field with type any. Although this field type can be useful for fields with dynamic data layout, it is strongly recommended to use JSON with json.RawMessage instead and implement custom marshaling.
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 ¶
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 ¶
Ints returns a new JSON Field with type []int.
func JSON ¶
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 Other ¶
Other represents a field that is not a good fit for any of the standard field types.
The second argument defines the GoType and must implement the ValueScanner interface. The SchemaType option must be set because the field type cannot be inferred. An example for defining Other field is as follows:
field.Other("link", &Link{}). SchemaType(map[string]string{ dialect.MySQL: "text", dialect.Postgres: "varchar", })
func String ¶
func String(name string) *stringBuilder
String returns a new Field with type string.
func Strings ¶
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 no effect.
func Time ¶
func Time(name string) *timeBuilder
Time returns a new Field with type timestamp.
func UUID ¶
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 ¶
type Annotation struct { // The StructTag option allows overriding the struct-tag // of the fields in the generated entity. For example: // // field.Annotation{ // StructTag: map[string]string{ // "id": `json:"id,omitempty" yaml:"-"`, // }, // } // StructTag map[string]string // ID defines a multi-field schema identifier. Note, // the annotation is valid only for edge schemas. // // func (TweetLike) Annotations() []schema.Annotation { // return []schema.Annotation{ // field.ID("user_id", "tweet_id"), // } // } // ID []string }
Annotation is a builtin schema annotation for configuring the schema fields in codegen.
func ID ¶
func ID(first, second string, fields ...string) *Annotation
ID defines a multi-field schema identifier. Note, the annotation is valid only for edge schemas.
func (TweetLike) Annotations() []schema.Annotation { return []schema.Annotation{ field.ID("user_id", "tweet_id"), } }
func (Annotation) Merge ¶
func (a Annotation) Merge(other schema.Annotation) schema.Annotation
Merge implements the schema.Merger interface.
func (Annotation) Name ¶
func (Annotation) Name() string
Name describes the annotation name.
type BinaryValueScanner ¶
type BinaryValueScanner[T interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler }] struct{}
BinaryValueScanner returns a new TypeValueScanner that calls MarshalBinary for storing values in the database, and calls UnmarshalBinary for scanning database values into struct fields.
func (BinaryValueScanner[T]) FromValue ¶
func (BinaryValueScanner[T]) FromValue(v driver.Value) (tv T, err error)
FromValue implements the TypeValueScanner.FromValue method.
func (BinaryValueScanner[T]) ScanValue ¶
func (BinaryValueScanner[T]) ScanValue() ValueScanner
ScanValue implements the TypeValueScanner.ScanValue method.
func (BinaryValueScanner[T]) Value ¶
func (BinaryValueScanner[T]) Value(v T) (driver.Value, error)
Value implements the TypeValueScanner.Value method.
type Descriptor ¶
type Descriptor struct { Tag string // struct tag. Size int // varchar size. Name string // field name. Info *TypeInfo // field type info. ValueScanner any // custom field codec. Unique bool // unique index of field. Nillable bool // nillable struct field. Optional bool // nullable field in database. Immutable bool // create only field. Default any // default value on create. UpdateDefault any // default value on update. Validators []any // validator functions. StorageKey string // sql column or gremlin property. Enums []struct{ N, V string } // enum values. Sensitive bool // sensitive info string field. SchemaType map[string]string // override the schema type. Annotations []schema.Annotation // field annotations. Comment string // field comment. Deprecated bool // mark the field as deprecated. DeprecatedReason string // deprecation reason. Err error }
A Descriptor for field configuration.
type EnumValues ¶
type EnumValues interface { Values() []string }
EnumValues defines the interface for getting the enum values.
type RType ¶
type RType struct { Name string // reflect.Type.Name Ident string // reflect.Type.String Kind reflect.Kind PkgPath string Methods map[string]struct{ In, Out []*RType } // contains filtered or unexported fields }
RType holds a serializable reflect.Type information of Go object. Used by the entc package.
func (*RType) Implements ¶
Implements reports whether the RType ~implements the given interface type.
func (*RType) IsPtr ¶
IsPtr reports if the reflect-type is a pointer type.
func (*RType) String ¶
RType returns the string value of the indirect reflect.Type.
func (*RType) TypeEqual ¶
TypeEqual reports if the underlying type is equal to the RType (after pointer indirections).
type TextValueScanner ¶
type TextValueScanner[T interface { encoding.TextMarshaler encoding.TextUnmarshaler }] struct{}
TextValueScanner returns a new TypeValueScanner that calls MarshalText for storing values in the database, and calls UnmarshalText for scanning database values into struct fields.
func (TextValueScanner[T]) FromValue ¶
func (TextValueScanner[T]) FromValue(v driver.Value) (tv T, err error)
FromValue implements the TypeValueScanner.FromValue method.
func (TextValueScanner[T]) ScanValue ¶
func (TextValueScanner[T]) ScanValue() ValueScanner
ScanValue implements the TypeValueScanner.ScanValue method.
func (TextValueScanner[T]) Value ¶
func (TextValueScanner[T]) Value(v T) (driver.Value, error)
Value implements the TypeValueScanner.Value method.
type Type ¶
type Type uint8
A Type represents a field type.
const ( TypeInvalid Type = iota TypeBool TypeTime TypeJSON TypeUUID TypeBytes TypeEnum TypeString TypeOther TypeInt8 TypeInt16 TypeInt32 TypeInt TypeInt64 TypeUint8 TypeUint16 TypeUint32 TypeUint TypeUint64 TypeFloat32 TypeFloat64 )
List of field types.
func (Type) ConstName ¶
ConstName returns the constant name of an info type. It's used by entc for printing the constant name in templates.
func (Type) Float ¶
Float reports if the given type is a float type.
func (Type) Integer ¶
Integer reports if the given type is an integral type.
func (Type) Numeric ¶
Numeric reports if the given type is a numeric type.
func (Type) String ¶
String returns the string representation of a type.
func (Type) Valid ¶
Valid reports if the given type if known type.
type TypeInfo ¶
type TypeInfo struct { Type Type Ident string PkgPath string // import path. PkgName string // local package name. 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 ¶
Comparable reports whether values of this type are comparable.
func (TypeInfo) ConstName ¶
ConstName returns the const name of the info type.
func (TypeInfo) Numeric ¶
Numeric reports if the given type is a numeric type.
func (TypeInfo) String ¶
String returns the string representation of a type.
func (TypeInfo) Stringer ¶
Stringer indicates if this type implements the Stringer interface.
func (TypeInfo) Valid ¶
Valid reports if the given type if known type.
func (TypeInfo) Validator ¶
Validator indicates if this type implements the Validator interface.
func (TypeInfo) ValueScanner ¶
ValueScanner indicates if this type implements the ValueScanner interface.
func (TypeInfo) Valuer ¶
Valuer indicates if this type implements the driver.Valuer interface.
type TypeValueScanner ¶
type TypeValueScanner[T any] interface { // Value returns the driver.Valuer for the GoType. Value(T) (driver.Value, error) // ScanValue returns a new ValueScanner that functions as an // intermediate result between database value and GoType value. // For example, sql.NullString or sql.NullInt. ScanValue() ValueScanner // FromValue returns the field instance from the ScanValue // above after the database value was scanned. FromValue(driver.Value) (T, error) }
TypeValueScanner is the interface that groups all methods for attaching an external ValueScanner to a custom GoType.
type Validator ¶
type Validator interface { Validate() error }
Validator interface wraps the Validate method. Custom GoTypes with this method will be validated when the entity is created or updated.
type ValueScanner ¶
ValueScanner is the interface that groups the Value and the Scan methods implemented by custom Go types.
type ValueScannerFunc ¶
type ValueScannerFunc[T any, S ValueScanner] struct { V func(T) (driver.Value, error) S func(S) (T, error) }
ValueScannerFunc is a wrapper for a function that implements the ValueScanner.
func (ValueScannerFunc[T, S]) FromValue ¶
func (f ValueScannerFunc[T, S]) FromValue(v driver.Value) (tv T, err error)
FromValue implements the TypeValueScanner.FromValue method.
func (ValueScannerFunc[T, S]) ScanValue ¶
func (f ValueScannerFunc[T, S]) ScanValue() ValueScanner
ScanValue implements the TypeValueScanner.ScanValue method.
func (ValueScannerFunc[T, S]) Value ¶
func (f ValueScannerFunc[T, S]) Value(t T) (driver.Value, error)
Value implements the TypeValueScanner.Value method.
Source Files ¶
annotation.go field.go numeric.go type.go
Directories ¶
Path | Synopsis |
---|---|
schema/field/internal | gen is a codegen cmd for generating numeric build types from template. |
- Version
- v0.14.4 (latest)
- Published
- Mar 17, 2025
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 3 hours ago –
Tools for package owners.