Documentation ¶
Index ¶
- Constants
- Variables
- func Enum(opts map[string]int32) *enum
- func ExtractMessageAnnotation(sch *gen.Type) (*message, error)
- func Field(num int, options ...FieldOption) schema.Annotation
- func Generate(g *gen.Graph, targetGoPackage string) error
- func Hook() gen.Hook
- func Message(opts ...MessageOption) schema.Annotation
- func Service(opts ...ServiceOption) schema.Annotation
- func Skip() schema.Annotation
- func SkipGen() schema.Annotation
- type Adapter
- func (a *Adapter) AllFileDescriptors() map[string]*desc.FileDescriptor
- func (a *Adapter) FieldMap(schemaName string) (FieldMap, error)
- func (a *Adapter) GetFileDescriptor(schemaName string) (*desc.FileDescriptor, error)
- func (a *Adapter) GetMessageDescriptor(schemaName string) (*desc.MessageDescriptor, error)
- type FieldMap
- type FieldMappingDescriptor
- type FieldOption
- type MessageOption
- type Method
- type ServiceOption
Constants ¶
const ( DefaultProtoPackageName = "entpb" IDFieldNumber = 1 NodesTypesEnumName = "EntityTypes" )
const (
EnumAnnotation = "ProtoEnum"
)
const FieldAnnotation = "ProtoField"
const MessageAnnotation = "ProtoMessage"
const SkipAnnotation = "ProtoSkip"
Variables ¶
var (
ErrEnumFieldsNotAnnotated = errors.New("entproto: all Enum options must be covered with an entproto.Enum annotation")
)
var (
ErrSchemaSkipped = errors.New("entproto: schema not annotated with Generate=true")
)
Functions ¶
func Field ¶
func Field(num int, options ...FieldOption) schema.Annotation
func Generate ¶
Generate takes a *gen.Graph and creates .proto files. Next to each .proto file, Generate creates a generate.go file containing a //go:generate directive to invoke protoc and compile Go code from the protobuf definitions. If generate.go already exists next to the .proto file, this step is skipped.
func Hook ¶
Hook returns a gen.Hook that invokes Generate. To use it programatically:
entc.Generate("./ent/schema", &gen.Config{ Hooks: []gen.Hook{ entproto.Hook(), }, })
func Message ¶
func Message(opts ...MessageOption) schema.Annotation
Message annotates an ent.Schema to specify that protobuf message generation is required for it.
func Service ¶
func Service(opts ...ServiceOption) schema.Annotation
Service annotates an ent.Schema to specify that protobuf service generation is required for it.
func Skip ¶
func Skip() schema.Annotation
Skip annotates an ent.Schema to specify that this field will be skipped during .proto generation.
func SkipGen ¶
func SkipGen() schema.Annotation
SkipGen annotates an ent.Schema to specify that protobuf message generation is not required for it. This is useful in cases where a schema ent.Mixin sets Generated to true and you want to specifically set it to false for this schema.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter facilitates the transformation of ent gen.Type to desc.FileDescriptors
func LoadAdapter ¶
LoadAdapter takes a *gen.Graph and parses it into protobuf file descriptors
func (*Adapter) AllFileDescriptors ¶
func (a *Adapter) AllFileDescriptors() map[string]*desc.FileDescriptor
AllFileDescriptors returns a file descriptor per proto package for each package that contains a successfully parsed ent.Schema
func (*Adapter) FieldMap ¶
FieldMap returns a FieldMap containing descriptors of all of the mappings between the ent schema field and the protobuf message's field descriptors.
func (*Adapter) GetFileDescriptor ¶
func (a *Adapter) GetFileDescriptor(schemaName string) (*desc.FileDescriptor, error)
GetFileDescriptor returns the proto file descriptor containing the transformed proto message descriptor for `schemaName` along with any other messages in the same protobuf package.
func (*Adapter) GetMessageDescriptor ¶
func (a *Adapter) GetMessageDescriptor(schemaName string) (*desc.MessageDescriptor, error)
GetMessageDescriptor retrieves the protobuf message descriptor for `schemaName`, if an error was returned while trying to parse that error they are returned
type FieldMap ¶
type FieldMap map[string]*FieldMappingDescriptor
FieldMap contains a mapping between the field's name in the ent schema and a FieldMappingDescriptor.
func (FieldMap) Edges ¶
func (m FieldMap) Edges() []*FieldMappingDescriptor
Edges returns the FieldMappingDescriptor for all of the edge fields of the schema. Items are sorted alphabetically on pb field name.
func (FieldMap) Enums ¶
func (m FieldMap) Enums() []*FieldMappingDescriptor
func (FieldMap) Fields ¶
func (m FieldMap) Fields() []*FieldMappingDescriptor
Fields returns the FieldMappingDescriptor for all of the fields of the schema. Items are sorted alphabetically on pb field name.
func (FieldMap) ID ¶
func (m FieldMap) ID() *FieldMappingDescriptor
ID returns the FieldMappingDescriptor for the ID field of the schema.
type FieldMappingDescriptor ¶
type FieldMappingDescriptor struct { EntField *gen.Field EntEdge *gen.Edge PbFieldDescriptor *desc.FieldDescriptor IsEdgeField bool IsIDField bool IsEnumFIeld bool ReferencedPbType *desc.MessageDescriptor }
FieldMappingDescriptor describes the mapping from a protobuf field descriptor to an ent Schema field
func (*FieldMappingDescriptor) EdgeIDPbStructField ¶
func (d *FieldMappingDescriptor) EdgeIDPbStructField() string
func (*FieldMappingDescriptor) EdgeIDPbStructFieldDesc ¶
func (d *FieldMappingDescriptor) EdgeIDPbStructFieldDesc() *desc.FieldDescriptor
func (*FieldMappingDescriptor) PbStructField ¶
func (d *FieldMappingDescriptor) PbStructField() string
type FieldOption ¶
type FieldOption func(*pbfield)
func Type ¶
func Type(typ descriptorpb.FieldDescriptorProto_Type) FieldOption
Type overrides the default mapping between ent types and protobuf types. Example:
field.Uint8("custom_pb"). Annotations( entproto.Field(2, entproto.Type(descriptorpb.FieldDescriptorProto_TYPE_UINT64), ), )
func TypeName ¶
func TypeName(n string) FieldOption
TypeName sets the pb descriptors type name, needed if the Type attribute is TYPE_ENUM or TYPE_MESSAGE.
type MessageOption ¶
type MessageOption func(msg *message)
MessageOption configures the entproto.Message annotation
func PackageName ¶
func PackageName(pkg string) MessageOption
PackageName modifies the generated message's protobuf package name
func TableNumber ¶
func TableNumber(index int32) MessageOption
TableNumber sets the index of the node in the node types enum
type Method ¶
type Method uint
const ( ServiceAnnotation = "ProtoService" // MaxPageSize is the maximum page size that can be returned by a List call. Requesting page sizes larger than // this value will return, at most, MaxPageSize entries. MaxPageSize = 1000 // MethodCreate generates a Create gRPC service method for the entproto.Service. MethodCreate Method = 1 << iota // MethodGet generates a Get gRPC service method for the entproto.Service. MethodGet // MethodUpdate generates an Update gRPC service method for the entproto.Service. MethodUpdate // MethodDelete generates a Delete gRPC service method for the entproto.Service. MethodDelete // MethodList generates a List gRPC service method for the entproto.Service. MethodList MethodListByRelatedTo MethodListByRelatedToPaginated // MethodAll generates all service methods for the entproto.Service. This is the same behavior as not including entproto.Methods. MethodAll = MethodCreate | MethodGet | MethodUpdate | MethodDelete | MethodList | MethodListByRelatedTo | MethodListByRelatedToPaginated )
type ServiceOption ¶
type ServiceOption func(svc *service)
ServiceOption configures the entproto.Service annotation.
func Methods ¶
func Methods(methods Method) ServiceOption
Methods specifies the gRPC service methods to generate for the entproto.Service.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
todo/ent/proto/entpb
Code generated by protoc-gen-entgrpc.
|
Code generated by protoc-gen-entgrpc. |