-
Notifications
You must be signed in to change notification settings - Fork 0
/
t_example_jel_test.go
47 lines (38 loc) · 963 Bytes
/
t_example_jel_test.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
package sqlb_test
import (
"fmt"
r "reflect"
"time"
"github.com/mitranim/sqlb"
)
func ExampleJel() {
type Internal struct {
InternalTime *time.Time `json:"internalTime" db:"internal_time"`
}
type External struct {
ExternalName string `json:"externalName" db:"external_name"`
Internal Internal `json:"internal" db:"internal"`
}
const src = `
["and",
["or",
false,
["=", "externalName", ["externalName", "literal string"]]
],
["and",
true,
["<", "internal.internalTime", ["internal.internalTime", "9999-01-01T00:00:00Z"]]
]
]
`
expr := sqlb.Jel{
Type: r.TypeOf((*External)(nil)).Elem(),
Text: src,
}
text, args := sqlb.Reify(expr)
fmt.Println(string(text))
fmt.Printf("%#v\n", args)
// Output:
// (($1 or ("external_name" = $2)) and ($3 and (("internal")."internal_time" < $4)))
// []interface {}{false, "literal string", true, time.Date(9999, time.January, 1, 0, 0, 0, 0, time.UTC)}
}