...
1 package exp
2
3 import (
4 "fmt"
5
6 "github.com/doug-martin/goqu/v9/internal/sb"
7 )
8
9
10 type (
11
12
13 Aliaseable interface {
14
15
16
17 As(interface{}) AliasedExpression
18 }
19
20
21 Castable interface {
22
23
24 Cast(val string) CastExpression
25 }
26
27 Inable interface {
28
29
30 In(...interface{}) BooleanExpression
31
32
33 NotIn(...interface{}) BooleanExpression
34 }
35
36 Isable interface {
37
38
39
40
41 Is(interface{}) BooleanExpression
42
43
44
45
46 IsNot(interface{}) BooleanExpression
47
48 IsNull() BooleanExpression
49
50 IsNotNull() BooleanExpression
51
52 IsTrue() BooleanExpression
53
54 IsNotTrue() BooleanExpression
55
56 IsFalse() BooleanExpression
57
58 IsNotFalse() BooleanExpression
59 }
60
61 Likeable interface {
62
63
64 Like(interface{}) BooleanExpression
65
66
67 NotLike(interface{}) BooleanExpression
68
69
70 ILike(interface{}) BooleanExpression
71
72
73 NotILike(interface{}) BooleanExpression
74
75
76
77 RegexpLike(interface{}) BooleanExpression
78
79
80 RegexpNotLike(interface{}) BooleanExpression
81
82
83 RegexpILike(interface{}) BooleanExpression
84
85
86 RegexpNotILike(interface{}) BooleanExpression
87 }
88
89
90 Comparable interface {
91
92
93 Eq(interface{}) BooleanExpression
94
95
96 Neq(interface{}) BooleanExpression
97
98
99 Gt(interface{}) BooleanExpression
100
101
102 Gte(interface{}) BooleanExpression
103
104
105 Lt(interface{}) BooleanExpression
106
107
108 Lte(interface{}) BooleanExpression
109 }
110
111
112 Distinctable interface {
113
114
115 Distinct() SQLFunctionExpression
116 }
117
118
119 Orderable interface {
120
121
122 Asc() OrderedExpression
123
124
125 Desc() OrderedExpression
126 }
127
128 Rangeable interface {
129
130
131 Between(RangeVal) RangeExpression
132
133
134 NotBetween(RangeVal) RangeExpression
135 }
136
137 Updateable interface {
138
139 Set(interface{}) UpdateExpression
140 }
141
142 Bitwiseable interface {
143
144
145 BitwiseInversion() BitwiseExpression
146
147
148 BitwiseOr(interface{}) BitwiseExpression
149
150
151 BitwiseAnd(interface{}) BitwiseExpression
152
153
154 BitwiseXor(interface{}) BitwiseExpression
155
156
157 BitwiseLeftShift(interface{}) BitwiseExpression
158
159
160 BitwiseRightShift(interface{}) BitwiseExpression
161 }
162 )
163
164 type (
165 Vals []interface{}
166
167 Expression interface {
168 Clone() Expression
169 Expression() Expression
170 }
171
172 SQLExpression interface {
173 Expression
174 ToSQL() (string, []interface{}, error)
175 IsPrepared() bool
176 }
177
178 AppendableExpression interface {
179 Expression
180 AppendSQL(b sb.SQLBuilder)
181
182 GetAs() IdentifierExpression
183
184
185
186 ReturnsColumns() bool
187 }
188
189
190
191 AliasedExpression interface {
192 Expression
193
194 Aliased() Expression
195
196 GetAs() IdentifierExpression
197
198
199 Schema(string) IdentifierExpression
200
201 Table(string) IdentifierExpression
202
203 Col(interface{}) IdentifierExpression
204
205
206 All() IdentifierExpression
207 }
208
209 BooleanOperation int
210 BooleanExpression interface {
211 Expression
212 Aliaseable
213
214 Op() BooleanOperation
215
216 LHS() Expression
217
218 RHS() interface{}
219 }
220
221 BitwiseOperation int
222 BitwiseExpression interface {
223 Expression
224 Aliaseable
225 Comparable
226 Isable
227 Inable
228 Likeable
229 Rangeable
230 Orderable
231 Distinctable
232
233 Op() BitwiseOperation
234
235 LHS() Expression
236
237 RHS() interface{}
238 }
239
240
241 CastExpression interface {
242 Expression
243 Aliaseable
244 Comparable
245 Inable
246 Isable
247 Likeable
248 Orderable
249 Distinctable
250 Rangeable
251
252 Casted() Expression
253
254 Type() LiteralExpression
255 }
256
257 ColumnListExpression interface {
258 Expression
259
260 Columns() []Expression
261
262 IsEmpty() bool
263
264 Append(...Expression) ColumnListExpression
265 }
266 CompoundType int
267 CompoundExpression interface {
268 Expression
269 Type() CompoundType
270 RHS() AppendableExpression
271 }
272
273 ConflictAction int
274 ConflictExpression interface {
275 Expression
276 Action() ConflictAction
277 }
278 ConflictUpdateExpression interface {
279 ConflictExpression
280 TargetColumn() string
281 Where(expressions ...Expression) ConflictUpdateExpression
282 WhereClause() ExpressionList
283 Update() interface{}
284 }
285 CommonTableExpression interface {
286 Expression
287 IsRecursive() bool
288
289 Name() LiteralExpression
290
291 SubQuery() Expression
292 }
293 ExpressionListType int
294
295
296
297 ExpressionList interface {
298 Expression
299
300 Type() ExpressionListType
301
302 Expressions() []Expression
303
304 Append(...Expression) ExpressionList
305
306 IsEmpty() bool
307 }
308
309 IdentifierExpression interface {
310 Expression
311 Aliaseable
312 Comparable
313 Inable
314 Isable
315 Likeable
316 Rangeable
317 Orderable
318 Updateable
319 Distinctable
320 Castable
321 Bitwiseable
322
323
324
325
326
327
328
329 IsQualified() bool
330
331 Schema(string) IdentifierExpression
332
333 GetSchema() string
334
335 Table(string) IdentifierExpression
336
337 GetTable() string
338
339 Col(interface{}) IdentifierExpression
340
341 GetCol() interface{}
342
343
344 All() IdentifierExpression
345
346
347 IsEmpty() bool
348 }
349 InsertExpression interface {
350 Expression
351 IsEmpty() bool
352 IsInsertFrom() bool
353 From() AppendableExpression
354 Cols() ColumnListExpression
355 SetCols(cols ColumnListExpression) InsertExpression
356 Vals() [][]interface{}
357 SetVals([][]interface{}) InsertExpression
358 }
359
360 JoinType int
361 JoinExpression interface {
362 Expression
363 JoinType() JoinType
364 IsConditioned() bool
365 Table() Expression
366 }
367
368 ConditionedJoinExpression interface {
369 JoinExpression
370 Condition() JoinCondition
371 IsConditionEmpty() bool
372 }
373 LateralExpression interface {
374 Expression
375 Aliaseable
376 Table() AppendableExpression
377 }
378
379
380
381
382 LiteralExpression interface {
383 Expression
384 Aliaseable
385 Comparable
386 Isable
387 Inable
388 Likeable
389 Rangeable
390 Orderable
391 Bitwiseable
392
393 Literal() string
394
395 Args() []interface{}
396 }
397
398 NullSortType int
399 SortDirection int
400
401 OrderedExpression interface {
402 Expression
403
404 SortExpression() Expression
405
406 IsAsc() bool
407
408 NullSortType() NullSortType
409
410 NullsFirst() OrderedExpression
411
412 NullsLast() OrderedExpression
413 }
414
415 RangeOperation int
416 RangeExpression interface {
417 Expression
418
419 Op() RangeOperation
420
421 LHS() Expression
422
423 RHS() RangeVal
424 }
425 RangeVal interface {
426 Start() interface{}
427 End() interface{}
428 }
429
430 Windowable interface {
431 Over(WindowExpression) SQLWindowFunctionExpression
432 OverName(IdentifierExpression) SQLWindowFunctionExpression
433 }
434
435
436 SQLFunctionExpression interface {
437 Expression
438 Aliaseable
439 Rangeable
440 Comparable
441 Orderable
442 Isable
443 Inable
444 Likeable
445 Windowable
446
447 Name() string
448
449 Args() []interface{}
450 }
451
452 UpdateExpression interface {
453 Col() IdentifierExpression
454 Val() interface{}
455 }
456
457 SQLWindowFunctionExpression interface {
458 Expression
459 Aliaseable
460 Rangeable
461 Comparable
462 Orderable
463 Isable
464 Inable
465 Likeable
466 Func() SQLFunctionExpression
467
468 Window() WindowExpression
469 WindowName() IdentifierExpression
470
471 HasWindow() bool
472 HasWindowName() bool
473 }
474
475 WindowExpression interface {
476 Expression
477
478 Name() IdentifierExpression
479 HasName() bool
480
481 Parent() IdentifierExpression
482 HasParent() bool
483 PartitionCols() ColumnListExpression
484 HasPartitionBy() bool
485 OrderCols() ColumnListExpression
486 HasOrder() bool
487
488 Inherit(parent string) WindowExpression
489 PartitionBy(cols ...interface{}) WindowExpression
490 OrderBy(cols ...interface{}) WindowExpression
491 }
492 CaseElse interface {
493 Result() interface{}
494 }
495 CaseWhen interface {
496 Condition() interface{}
497 Result() interface{}
498 }
499 CaseExpression interface {
500 Expression
501 Aliaseable
502 Orderable
503 GetValue() interface{}
504 GetWhens() []CaseWhen
505 GetElse() CaseElse
506 Value(val interface{}) CaseExpression
507 When(condition, result interface{}) CaseExpression
508 Else(result interface{}) CaseExpression
509 }
510 )
511
512 const (
513 UnionCompoundType CompoundType = iota
514 UnionAllCompoundType
515 IntersectCompoundType
516 IntersectAllCompoundType
517
518 DoNothingConflictAction ConflictAction = iota
519 DoUpdateConflictAction
520
521 AndType ExpressionListType = iota
522 OrType
523
524 InnerJoinType JoinType = iota
525 FullOuterJoinType
526 RightOuterJoinType
527 LeftOuterJoinType
528 FullJoinType
529 RightJoinType
530 LeftJoinType
531 NaturalJoinType
532 NaturalLeftJoinType
533 NaturalRightJoinType
534 NaturalFullJoinType
535 CrossJoinType
536
537 UsingJoinCondType JoinConditionType = iota
538 OnJoinCondType
539
540
541 NoNullsSortType NullSortType = iota
542
543 NullsFirstSortType
544
545 NullsLastSortType
546
547 AscDir SortDirection = iota
548
549 DescSortDir
550
551
552 BetweenOp RangeOperation = iota
553
554 NotBetweenOp
555
556
557 EqOp BooleanOperation = iota
558
559 NeqOp
560
561 IsOp
562
563 IsNotOp
564
565 GtOp
566
567 GteOp
568
569 LtOp
570
571 LteOp
572
573 InOp
574
575 NotInOp
576
577 LikeOp
578
579 NotLikeOp
580
581 ILikeOp
582
583 NotILikeOp
584
585 RegexpLikeOp
586
587 RegexpNotLikeOp
588
589 RegexpILikeOp
590
591 RegexpNotILikeOp
592
593 betweenStr = "between"
594
595 BitwiseInversionOp BitwiseOperation = iota
596 BitwiseOrOp
597 BitwiseAndOp
598 BitwiseXorOp
599 BitwiseLeftShiftOp
600 BitwiseRightShiftOp
601 )
602
603 var (
604 ConditionedJoinTypes = map[JoinType]bool{
605 InnerJoinType: true,
606 FullOuterJoinType: true,
607 RightOuterJoinType: true,
608 LeftOuterJoinType: true,
609 FullJoinType: true,
610 RightJoinType: true,
611 LeftJoinType: true,
612 }
613
614 operatorInversions = map[BooleanOperation]BooleanOperation{
615 IsOp: IsNotOp,
616 EqOp: NeqOp,
617 GtOp: LteOp,
618 GteOp: LtOp,
619 LtOp: GteOp,
620 LteOp: GtOp,
621 InOp: NotInOp,
622 LikeOp: NotLikeOp,
623 ILikeOp: NotILikeOp,
624 RegexpLikeOp: RegexpNotLikeOp,
625 RegexpILikeOp: RegexpNotILikeOp,
626 IsNotOp: IsOp,
627 NeqOp: EqOp,
628 NotInOp: InOp,
629 NotLikeOp: LikeOp,
630 NotILikeOp: ILikeOp,
631 RegexpNotLikeOp: RegexpLikeOp,
632 RegexpNotILikeOp: RegexpILikeOp,
633 }
634 )
635
636 func (bo BooleanOperation) String() string {
637 switch bo {
638 case EqOp:
639 return "eq"
640 case NeqOp:
641 return "neq"
642 case IsOp:
643 return "is"
644 case IsNotOp:
645 return "isnot"
646 case GtOp:
647 return "gt"
648 case GteOp:
649 return "gte"
650 case LtOp:
651 return "lt"
652 case LteOp:
653 return "lte"
654 case InOp:
655 return "in"
656 case NotInOp:
657 return "notin"
658 case LikeOp:
659 return "like"
660 case NotLikeOp:
661 return "notlike"
662 case ILikeOp:
663 return "ilike"
664 case NotILikeOp:
665 return "notilike"
666 case RegexpLikeOp:
667 return "regexplike"
668 case RegexpNotLikeOp:
669 return "regexpnotlike"
670 case RegexpILikeOp:
671 return "regexpilike"
672 case RegexpNotILikeOp:
673 return "regexpnotilike"
674 }
675 return fmt.Sprintf("%d", bo)
676 }
677
678 func (bi BitwiseOperation) String() string {
679 switch bi {
680 case BitwiseInversionOp:
681 return "Inversion"
682 case BitwiseOrOp:
683 return "OR"
684 case BitwiseAndOp:
685 return "AND"
686 case BitwiseXorOp:
687 return "XOR"
688 case BitwiseLeftShiftOp:
689 return "Left Shift"
690 case BitwiseRightShiftOp:
691 return "Right Shift"
692 }
693 return fmt.Sprintf("%d", bi)
694 }
695
696 func (ro RangeOperation) String() string {
697 switch ro {
698 case BetweenOp:
699 return betweenStr
700 case NotBetweenOp:
701 return "not between"
702 }
703 return fmt.Sprintf("%d", ro)
704 }
705
706 func (jt JoinType) String() string {
707 switch jt {
708 case InnerJoinType:
709 return "InnerJoinType"
710 case FullOuterJoinType:
711 return "FullOuterJoinType"
712 case RightOuterJoinType:
713 return "RightOuterJoinType"
714 case LeftOuterJoinType:
715 return "LeftOuterJoinType"
716 case FullJoinType:
717 return "FullJoinType"
718 case RightJoinType:
719 return "RightJoinType"
720 case LeftJoinType:
721 return "LeftJoinType"
722 case NaturalJoinType:
723 return "NaturalJoinType"
724 case NaturalLeftJoinType:
725 return "NaturalLeftJoinType"
726 case NaturalRightJoinType:
727 return "NaturalRightJoinType"
728 case NaturalFullJoinType:
729 return "NaturalFullJoinType"
730 case CrossJoinType:
731 return "CrossJoinType"
732 }
733 return fmt.Sprintf("%d", jt)
734 }
735
View as plain text