github.com/mitranim/sqlb@v0.7.2/t_jel_test.go (about) 1 package sqlb 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func Test_Jel_Transcode(t *testing.T) { 9 type Internal struct { 10 InternalTime *time.Time `json:"internalTime" db:"internal_time"` 11 } 12 13 type External struct { 14 ExternalName string `json:"externalName" db:"external_name"` 15 Internal Internal `json:"internal" db:"internal"` 16 } 17 18 const src = ` 19 ["and", 20 ["or", 21 false, 22 ["=", "externalName", ["externalName", "literal string"]] 23 ], 24 ["and", 25 true, 26 ["<", "internal.internalTime", ["internal.internalTime", "9999-01-01T00:00:00Z"]] 27 ] 28 ] 29 ` 30 31 expr := Jel{typeElemOf((*External)(nil)), src} 32 text, args := Reify(expr) 33 34 eq( 35 t, 36 `(($1 or ("external_name" = $2)) and ($3 and (("internal")."internal_time" < $4)))`, 37 text, 38 ) 39 40 eq( 41 t, 42 []any{false, `literal string`, true, parseTime(`9999-01-01T00:00:00Z`)}, 43 args, 44 ) 45 }