Documentation ¶
Index ¶
- Constants
- Variables
- func Enum(opts map[string]int32) *enum
- func Field(num int, options ...FieldOption) schema.Annotation
- func Generate(g *gen.Graph) error
- func Hook() gen.Hook
- func Message(opts ...MessageOption) schema.Annotation
- func Service() 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
Constants ¶
const ( DefaultProtoPackageName = "entpb" IDFieldNumber = 1 )
const (
EnumAnnotation = "ProtoEnum"
)
const FieldAnnotation = "ProtoField"
const MessageAnnotation = "ProtoMessage"
const (
ServiceAnnotation = "ProtoService"
)
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() schema.Annotation
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
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
todo/ent/proto/entpb
Code generated by protoc-gen-entgrpc.
|
Code generated by protoc-gen-entgrpc. |