-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.go
50 lines (45 loc) · 1.26 KB
/
field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package ens
import (
"github.com/things-go/ens/proto"
"github.com/things-go/ens/rapier"
"google.golang.org/protobuf/reflect/protoreflect"
)
type FieldDescriptor struct {
ColumnName string // 列名, snake case
Comment string // 注释
Nullable bool // Nullable reports whether the column may be null.
Column ColumnDef
// for go
Type GoType // go type information.
GoName string // Go name
GoPointer bool // go field is pointer.
Tags []string // Tags struct tag
}
func (field *FieldDescriptor) GoType(typ any) {
field.Type = NewGoType(field.Type.Type, typ)
}
func (field *FieldDescriptor) IntoProto() *proto.MessageField {
goType := field.Type
k, n := goType.Type.IntoProtoKind()
cardinality := protoreflect.Required
if field.Nullable {
cardinality = protoreflect.Optional
}
return &proto.MessageField{
Cardinality: cardinality,
Type: k,
TypeName: n,
Name: field.ColumnName,
ColumnName: field.ColumnName,
Comment: field.Comment,
}
}
func (field *FieldDescriptor) IntoRapier() *rapier.StructField {
return &rapier.StructField{
Type: field.Type.Type.IntoRapierType(),
GoName: field.GoName,
Nullable: field.Nullable,
ColumnName: field.ColumnName,
Comment: field.Comment,
}
}