-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (36 loc) · 1.02 KB
/
main.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
package main
import (
"github.com/lennartolsen/godsl/dsl"
"fmt"
"github.com/lennartolsen/godsl/classroom"
"github.com/lennartolsen/godsl/dsl/generators"
)
func main() {
dsl.RegisterCollectionType("classroom", classroom.Classroom{})
dsl.RegisterEntityType("teacher", classroom.Teacher{})
dsl.RegisterEntityType("student", classroom.Student{})
/**
* Consider making generic attribute types, like string, int, float etc in the dsl
* More complex types could reside in the persons instance
*/
dsl.RegisterAttributeType("name", classroom.String{})
dsl.RegisterAttributeType("age", classroom.Integer64{})
classroom := dsl.NewCollection("classroom").
Entity("teacher").
Attribute("name").
Attribute("age").
Entity("student").
Attribute("name").
Attribute("age").
Flush()
generators.Code(classroom)
classroom.
Append("teacher",
dsl.V{"name", "lennart"},
dsl.V{"age", 17},
dsl.V{"grade", 4}).
Append("student",
dsl.V{"name", "lennart"})
str := classroom.ToString()
fmt.Println(str)
}