-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
46 lines (41 loc) · 1.01 KB
/
schema.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
package ens
import (
"github.com/things-go/ens/proto"
"github.com/things-go/ens/rapier"
"github.com/things-go/ens/sqlx"
)
// Schema
type Schema struct {
Name string // schema name
Entities []*EntityDescriptor // schema entity.
}
func (s *Schema) IntoProto() *proto.Schema {
entities := make([]*proto.Message, 0, len(s.Entities))
for _, entity := range s.Entities {
entities = append(entities, entity.IntoProto())
}
return &proto.Schema{
Name: s.Name,
Entities: entities,
}
}
func (s *Schema) IntoRapier() *rapier.Schema {
entities := make([]*rapier.Struct, 0, len(s.Entities))
for _, entity := range s.Entities {
entities = append(entities, entity.IntoRapier())
}
return &rapier.Schema{
Name: s.Name,
Entities: entities,
}
}
func (s *Schema) IntoSQL() *sqlx.Schema {
entities := make([]*sqlx.Table, 0, len(s.Entities))
for _, entity := range s.Entities {
entities = append(entities, entity.IntoSQL())
}
return &sqlx.Schema{
Name: s.Name,
Entities: entities,
}
}