gitee.com/eden-framework/sqlx@v0.0.3/builder/addition_combination.go (about) 1 package builder 2 3 import ( 4 "context" 5 ) 6 7 type CombinationAddition struct { 8 } 9 10 func (CombinationAddition) AdditionType() AdditionType { 11 return AdditionCombination 12 } 13 14 func Union() *combination { 15 return &combination{ 16 operator: "UNION", 17 } 18 } 19 20 func Intersect() *combination { 21 return &combination{ 22 operator: "INTERSECT", 23 } 24 } 25 26 func Expect() *combination { 27 return &combination{ 28 operator: "EXCEPT", 29 } 30 } 31 32 var _ Addition = (*combination)(nil) 33 34 type combination struct { 35 CombinationAddition 36 operator string // UNION | INTERSECT | EXCEPT 37 method string // ALL | DISTINCT 38 stmtSelect SelectStatement 39 } 40 41 func (c *combination) IsNil() bool { 42 return c == nil || IsNilExpr(c.stmtSelect) 43 } 44 45 func (c combination) All(stmtSelect SelectStatement) *combination { 46 c.method = "ALL" 47 c.stmtSelect = stmtSelect 48 return &c 49 } 50 51 func (c combination) Distinct(stmtSelect SelectStatement) *combination { 52 c.method = "DISTINCT" 53 c.stmtSelect = stmtSelect 54 return &c 55 } 56 57 func (c *combination) Ex(ctx context.Context) *Ex { 58 e := Expr(c.operator) 59 e.WriteByte(' ') 60 61 if c.method != "" { 62 e.WriteString(c.method) 63 e.WriteByte(' ') 64 } 65 66 e.WriteExpr(c.stmtSelect) 67 68 return e.Ex(ctx) 69 }