yay, where in works
This commit is contained in:
		
							parent
							
								
									d18203ee62
								
							
						
					
					
						commit
						4587a8a686
					
				| @ -3,7 +3,7 @@ | ||||
| Yet Another ORM library for Go, aims for developer friendly | ||||
| 
 | ||||
| ## TODO | ||||
| * Complex where query (= / > / < / <> / in) | ||||
| * Complex where query (in) | ||||
| * Order | ||||
| * Limit | ||||
| * Select | ||||
|  | ||||
| @ -180,4 +180,12 @@ func TestComplexWhere(t *testing.T) { | ||||
| 	if len(users) != 2 { | ||||
| 		t.Errorf("Should only found 2 users's birthday <= t2, but have %v", len(users)) | ||||
| 	} | ||||
| 
 | ||||
| 	users = []User{} | ||||
| 	a := db.Where("name in (?)", []string{"1", "3"}).Find(&users) | ||||
| 	a.db.Query("SELECT * FROM users WHERE ( name in ($1) )", "'1', '2'") | ||||
| 
 | ||||
| 	if len(users) != 3 { | ||||
| 		t.Errorf("Should only found 3 users's name in (1, 3), but have %v", len(users)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										15
									
								
								sql.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								sql.go
									
									
									
									
									
								
							| @ -144,7 +144,20 @@ func (s *Orm) whereSql() (sql string) { | ||||
| 			str := "( " + clause["query"].(string) + " )" | ||||
| 			args := clause["args"].([]interface{}) | ||||
| 			for _, arg := range args { | ||||
| 				str = strings.Replace(str, "?", s.addToVars(arg), 1) | ||||
| 
 | ||||
| 				switch arg.(type) { | ||||
| 				case []string, []int, []int64, []int32: | ||||
| 					var temp_marks []string | ||||
| 					for _ = range arg.([]string) { | ||||
| 						temp_marks = append(temp_marks, "?") | ||||
| 					} | ||||
| 					str = strings.Replace(str, "?", strings.Join(temp_marks, ","), 1) | ||||
| 					for _, a := range arg.([]string) { | ||||
| 						str = strings.Replace(str, "?", s.addToVars(a), 1) | ||||
| 					} | ||||
| 				default: | ||||
| 					str = strings.Replace(str, "?", s.addToVars(arg), 1) | ||||
| 				} | ||||
| 			} | ||||
| 			conditions = append(conditions, str) | ||||
| 		} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu