Version: v0.10.1 Latest Latest

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

Go to latest
Published: Mar 4, 2022 License: Apache-2.0 Imports: 22 Imported by: 0



Package load is the interface for loading an ent/schema package into a Go program.



This section is empty.


This section is empty.


func MarshalSchema

func MarshalSchema(schema ent.Interface) (b []byte, err error)

MarshalSchema encodes the ent.Schema interface into a JSON that can be decoded into the Schema objects declared above.


type Config

type Config struct {
	// Path is the path for the schema package.
	Path string
	// Names are the schema names to load. Empty means all schemas in the directory.
	Names []string

Config holds the configuration for loading an ent/schema package.

func (*Config) Load

func (c *Config) Load() (*SchemaSpec, error)

Load loads the schemas package and build the Go plugin with this info.

type Edge

type Edge struct {
	Name        string                 `json:"name,omitempty"`
	Type        string                 `json:"type,omitempty"`
	Tag         string                 `json:"tag,omitempty"`
	Field       string                 `json:"field,omitempty"`
	RefName     string                 `json:"ref_name,omitempty"`
	Ref         *Edge                  `json:"ref,omitempty"`
	Unique      bool                   `json:"unique,omitempty"`
	Inverse     bool                   `json:"inverse,omitempty"`
	Required    bool                   `json:"required,omitempty"`
	StorageKey  *edge.StorageKey       `json:"storage_key,omitempty"`
	Annotations map[string]interface{} `json:"annotations,omitempty"`

Edge represents an ent.Edge that was loaded from a complied user package.

func NewEdge

func NewEdge(ed *edge.Descriptor) *Edge

NewEdge creates an loaded edge from edge descriptor.

type Field

type Field struct {
	Name          string                  `json:"name,omitempty"`
	Info          *field.TypeInfo         `json:"type,omitempty"`
	Tag           string                  `json:"tag,omitempty"`
	Size          *int64                  `json:"size,omitempty"`
	Enums         []struct{ N, V string } `json:"enums,omitempty"`
	Unique        bool                    `json:"unique,omitempty"`
	Nillable      bool                    `json:"nillable,omitempty"`
	Optional      bool                    `json:"optional,omitempty"`
	Default       bool                    `json:"default,omitempty"`
	DefaultValue  interface{}             `json:"default_value,omitempty"`
	DefaultKind   reflect.Kind            `json:"default_kind,omitempty"`
	UpdateDefault bool                    `json:"update_default,omitempty"`
	Immutable     bool                    `json:"immutable,omitempty"`
	Validators    int                     `json:"validators,omitempty"`
	StorageKey    string                  `json:"storage_key,omitempty"`
	Position      *Position               `json:"position,omitempty"`
	Sensitive     bool                    `json:"sensitive,omitempty"`
	SchemaType    map[string]string       `json:"schema_type,omitempty"`
	Annotations   map[string]interface{}  `json:"annotations,omitempty"`
	Comment       string                  `json:"comment,omitempty"`

Field represents an ent.Field that was loaded from a complied user package.

func NewField

func NewField(fd *field.Descriptor) (*Field, error)

NewField creates a loaded field from field descriptor.

type Index

type Index struct {
	Unique      bool                   `json:"unique,omitempty"`
	Edges       []string               `json:"edges,omitempty"`
	Fields      []string               `json:"fields,omitempty"`
	StorageKey  string                 `json:"storage_key,omitempty"`
	Annotations map[string]interface{} `json:"annotations,omitempty"`

Index represents an ent.Index that was loaded from a complied user package.

func NewIndex

func NewIndex(idx *index.Descriptor) *Index

NewIndex creates an loaded index from index descriptor.

type Position

type Position struct {
	Index      int  // Index in the field/hook list.
	MixedIn    bool // Indicates if the schema object was mixed-in.
	MixinIndex int  // Mixin index in the mixin list.

Position describes a position in the schema.

type Schema

type Schema struct {
	Name        string                 `json:"name,omitempty"`
	Config      ent.Config             `json:"config,omitempty"`
	Edges       []*Edge                `json:"edges,omitempty"`
	Fields      []*Field               `json:"fields,omitempty"`
	Indexes     []*Index               `json:"indexes,omitempty"`
	Hooks       []*Position            `json:"hooks,omitempty"`
	Policy      []*Position            `json:"policy,omitempty"`
	Annotations map[string]interface{} `json:"annotations,omitempty"`

Schema represents an ent.Schema that was loaded from a complied user package.

func UnmarshalSchema

func UnmarshalSchema(buf []byte) (*Schema, error)

UnmarshalSchema decodes the given buffer to a loaded schema.

type SchemaSpec

type SchemaSpec struct {
	// Schemas defines the loaded schema descriptors.
	Schemas []*Schema

	// PkgPath is the package path of the loaded
	// ent.Schema package.
	PkgPath string

	// Module defines the module information for
	// the user schema package if exists.
	Module *packages.Module

A SchemaSpec holds a serializable version of an ent.Schema and its Go package and module information.

Source Files

Jump to

Keyboard shortcuts

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