New Comma Expression (#4524)
* Add new comma expression * Add comma expression unit test
This commit is contained in:
		
							parent
							
								
									d4f3c109d6
								
							
						
					
					
						commit
						ac97aec513
					
				| @ -43,3 +43,17 @@ func (s Select) MergeClause(clause *Clause) { | ||||
| 		clause.Expression = s | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // CommaExpression represents a group of expressions separated by commas.
 | ||||
| type CommaExpression struct { | ||||
| 	Exprs []Expression | ||||
| } | ||||
| 
 | ||||
| func (comma CommaExpression) Build(builder Builder) { | ||||
| 	for idx, expr := range comma.Exprs { | ||||
| 		if idx > 0 { | ||||
| 			_, _ = builder.WriteString(", ") | ||||
| 		} | ||||
| 		expr.Build(builder) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -31,6 +31,18 @@ func TestSelect(t *testing.T) { | ||||
| 			}, clause.From{}}, | ||||
| 			"SELECT `name` FROM `users`", nil, | ||||
| 		}, | ||||
| 		{ | ||||
| 			[]clause.Interface{clause.Select{ | ||||
| 				Expression: clause.CommaExpression{ | ||||
| 					Exprs: []clause.Expression{ | ||||
| 						clause.NamedExpr{"?", []interface{}{clause.Column{Name: "id"}}}, | ||||
| 						clause.NamedExpr{"?", []interface{}{clause.Column{Name: "name"}}}, | ||||
| 						clause.NamedExpr{"LENGTH(?)", []interface{}{clause.Column{Name: "mobile"}}}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, clause.From{}}, | ||||
| 			"SELECT `id`, `name`, LENGTH(`mobile`) FROM `users`", nil, | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	for idx, result := range results { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 River
						River