@@ -16,6 +16,7 @@ package ast
16
16
17
17
import (
18
18
"fmt"
19
+ "strings"
19
20
"text/scanner"
20
21
21
22
"gopkg.in/spacemonkeygo/dbx.v1/consts"
@@ -241,17 +242,73 @@ func (j *JoinType) Get() consts.JoinType {
241
242
242
243
type Where struct {
243
244
Pos scanner.Position
244
- Left * FieldRef
245
+ Left * Expr
245
246
Op * Operator
246
- Right * FieldRef
247
+ Right * Expr
247
248
}
248
249
249
250
func (w * Where ) String () string {
250
- right := "?"
251
- if w .Right != nil {
252
- right = w .Right .String ()
251
+ return fmt .Sprintf ("%s %s %s" , w .Left , w .Op , w .Right )
252
+ }
253
+
254
+ type Expr struct {
255
+ Pos scanner.Position
256
+ // The following fields are mutually exclusive
257
+ Null * Null
258
+ StringLit * String
259
+ NumberLit * String
260
+ Placeholder * Placeholder
261
+ FieldRef * FieldRef
262
+ FuncCall * FuncCall
263
+ }
264
+
265
+ func (e * Expr ) String () string {
266
+ switch {
267
+ case e .Null != nil :
268
+ return e .Null .String ()
269
+ case e .StringLit != nil :
270
+ return fmt .Sprintf ("%q" , e .StringLit .Value )
271
+ case e .NumberLit != nil :
272
+ return e .NumberLit .Value
273
+ case e .Placeholder != nil :
274
+ return e .Placeholder .String ()
275
+ case e .FieldRef != nil :
276
+ return e .FieldRef .String ()
277
+ case e .FuncCall != nil :
278
+ return e .FuncCall .String ()
279
+ default :
280
+ return ""
281
+ }
282
+ }
283
+
284
+ type Null struct {
285
+ Pos scanner.Position
286
+ }
287
+
288
+ func (p * Null ) String () string {
289
+ return "null"
290
+ }
291
+
292
+ type Placeholder struct {
293
+ Pos scanner.Position
294
+ }
295
+
296
+ func (p * Placeholder ) String () string {
297
+ return "?"
298
+ }
299
+
300
+ type FuncCall struct {
301
+ Pos scanner.Position
302
+ Name * String
303
+ Args []* Expr
304
+ }
305
+
306
+ func (f * FuncCall ) String () string {
307
+ var args []string
308
+ for _ , arg := range f .Args {
309
+ args = append (args , arg .String ())
253
310
}
254
- return fmt .Sprintf ("%s %s %s " , w . Left , w . Op , right )
311
+ return fmt .Sprintf ("%s(%s) " , f . Name . Value , strings . Join ( args , ", " ) )
255
312
}
256
313
257
314
type Operator struct {
0 commit comments