Documentation ¶
Overview ¶
Package ent is the interface between end-user schemas and entc (ent codegen).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // A Table is an optional table name defined for the schema. Table string }
A Config structure is used to configure an entity schema. The usage of this structure is as follows:
func (T) Config() ent.Config { return ent.Config{ Table: "Name", } }
type Edge ¶
type Edge interface {
Descriptor() *edge.Descriptor
}
A Edge interface returns an edge descriptor for vertex edges. The usage for the interface is as follows:
func (T) Edges() []ent.Edge { return []ent.Edge{ edge.To("S", S.Type), } }
type Field ¶
type Field interface {
Descriptor() *field.Descriptor
}
A Field interface returns a field descriptor for vertex fields/properties. The usage for the interface is as follows:
func (T) Fields() []ent.Field { return []ent.Field{ field.Int("int"), } }
type Hook ¶
Hook defines the "mutation middleware". A function that gets a Mutator and returns a Mutator. For example:
hook := func(next ent.Mutator) ent.Mutator { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { fmt.Printf("Type: %s, Operation: %s, ConcreteType: %T\n", m.Type(), m.Op(), m) return next.Mutate(ctx, m) }) }
type Index ¶
type Index interface {
Descriptor() *index.Descriptor
}
A Index interface returns an index descriptor for vertex indexes. The usage for the interface is as follows:
func (T) Indexes() []ent.Index { return []ent.Index{ index.Fields("f1", "f2"). Unique(), } }
type Interface ¶
type Interface interface { // Type is a dummy method, that is used in edge declaration. // // The Type method should be used as follows: // // type S struct { ent.Schema } // // type T struct { ent.Schema } // // func (T) Edges() []ent.Edge { // return []ent.Edge{ // edge.To("S", S.Type), // } // } // Type() // Fields returns the fields of the schema. Fields() []Field // Edges returns the edges of the schema. Edges() []Edge // Indexes returns the indexes of the schema. Indexes() []Index // Config returns an optional config for the schema. Config() Config // Mixin returns an optional list of Mixin to extends // the schema. Mixin() []Mixin // Hooks returns an optional list of Hook to apply on // mutations. Hooks() []Hook // Policy returns the privacy policy of the schema. Policy() Policy }
The Interface type describes the requirements for an exported type defined in the schema package. It functions as the interface between the user's schema types and codegen loader. Users should use the Schema type for embedding as follows:
type T struct { ent.Schema }
type Mixin ¶
type Mixin interface { // Fields returns a slice of fields to be added // to the schema fields. Fields() []Field }
The Mixin type describes a set of methods that can extend other methods in the schema without calling them directly.
type TimeMixin struct {} func (TimeMixin) Fields() []ent.Field { return []ent.Field{ field.Time("created_at"). Immutable(). Default(time.Now), field.Time("updated_at"). Default(time.Now). UpdateDefault(time.Now), } } type T struct { ent.Schema } func(T) Mixin() []ent.Mixin { return []ent.Mixin{ TimeMixin{}, } }
type MutateFunc ¶
The MutateFunc type is an adapter to allow the use of ordinary function as mutator. If f is a function with the appropriate signature, MutateFunc(f) is a Mutator that calls f.
type Mutation ¶
type Mutation interface { // Op returns the operation name generated by entc. Op() Op // Type returns the schema type for this mutation. Type() string // Fields returns all fields that were changed during // this mutation. Note that, in order to get all numeric // fields that were in/decremented, call AddedFields(). Fields() []string // Field returns the value of a field with the given name. // The second boolean value indicates that this field was // not set, or was not define in the schema. Field(name string) (Value, bool) // SetField sets the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. SetField(name string, value Value) error // AddedFields returns all numeric fields that were incremented // or decremented during this mutation. AddedFields() []string // AddedField returns the numeric value that was in/decremented // from a field with the given name. The second value indicates // that this field was not set, or was not define in the schema. AddedField(name string) (Value, bool) // AddField adds the value for the given name. It returns an // error if the field is not defined in the schema, or if the // type mismatch the field type. AddField(name string, value Value) error // ClearedFields returns all nullable fields that were cleared // during this mutation. ClearedFields() []string // FieldCleared returns a boolean indicates if this field was // cleared in this mutation. FieldCleared(name string) bool // ClearField clears the value for the given name. It returns an // error if the field is not defined in the schema. ClearField(name string) error // ResetField resets all changes in the mutation regarding the // given field name. It returns an error if the field is not // defined in the schema. ResetField(name string) error // AddedEdges returns all edge names that were set/added in this // mutation. AddedEdges() []string // AddedIDs returns all ids (to other nodes) that were added for // the given edge name. AddedIDs(name string) []Value // RemovedEdges returns all edge names that were removed in this // mutation. RemovedEdges() []string // RemovedIDs returns all ids (to other nodes) that were removed for // the given edge name. RemovedIDs(name string) []Value // ClearedEdges returns all edge names that were cleared in this // mutation. ClearedEdges() []string // EdgeCleared returns a boolean indicates if this edge was // cleared in this mutation. EdgeCleared(name string) bool // ClearEdge clears the value for the given name. It returns an // error if the edge name is not defined in the schema. ClearEdge(name string) error // ResetEdge resets all changes in the mutation regarding the // given edge name. It returns an error if the edge is not // defined in the schema. ResetEdge(name string) error }
Mutation represents an operation that mutate the graph. For example, adding a new node, updating many, or dropping data. The implementation is generated by entc (ent codegen).
type Mutator ¶
type Mutator interface { // Mutate apply the given mutation on the graph. Mutate(context.Context, Mutation) (Value, error) }
Mutator is the interface that wraps the Mutate method.
type Op ¶
type Op uint
An Op represents a mutation operation.
type Policy ¶
type Policy interface { EvalMutation(context.Context, Mutation) error EvalQuery(context.Context, Query) error }
The Policy type defines the write privacy policy of an entity. The usage for the interface is as follows:
type T struct { ent.Schema }
func(T) Policy() ent.Policy { return privacy.AlwaysAllowReadWrite() }
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
gremlin/graph/dsl
Package dsl provide an API for writing gremlin dsl queries almost as-is in Go without using strings in the code.
|
Package dsl provide an API for writing gremlin dsl queries almost as-is in Go without using strings in the code. |
sql/schema
Package schema contains all schema migration logic for SQL dialects.
|
Package schema contains all schema migration logic for SQL dialects. |
sql/sqlgraph
sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen.
|
sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen. |
Package entc provides an interface for interacting with entc (ent codegen) as a package rather than an executable.
|
Package entc provides an interface for interacting with entc (ent codegen) as a package rather than an executable. |
gen
Package gen is the interface for generating loaded schemas into a Go package.
|
Package gen is the interface for generating loaded schemas into a Go package. |
gen/internal
Package internal Code generated by go-bindata.
|
Package internal Code generated by go-bindata. |
load
Package load is the interface for loading schema package into a Go program.
|
Package load is the interface for loading schema package into a Go program. |
load/internal
Package internal Code generated by go-bindata.
|
Package internal Code generated by go-bindata. |
examples
|
|
schema
|
|
field/gen
gen is a codegen cmd for generating numeric build types from template.
|
gen is a codegen cmd for generating numeric build types from template. |