quote map for utils
This commit is contained in:
		
							parent
							
								
									11758c647f
								
							
						
					
					
						commit
						c26e10813d
					
				
							
								
								
									
										5
									
								
								orm.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								orm.go
									
									
									
									
									
								
							| @ -11,6 +11,7 @@ import ( | ||||
| type Orm struct { | ||||
| 	TableName  string | ||||
| 	PrimaryKey string | ||||
| 	SqlResult  sql.Result | ||||
| 	Error      error | ||||
| 	Sql        string | ||||
| 	SqlVars    []interface{} | ||||
| @ -105,9 +106,9 @@ func (s *Orm) Updates(values map[string]string) *Orm { | ||||
| 
 | ||||
| func (s *Orm) Exec(sql ...string) *Orm { | ||||
| 	if len(sql) == 0 { | ||||
| 		s.db.Exec(s.Sql, s.SqlVars...) | ||||
| 		s.SqlResult, s.Error = s.db.Exec(s.Sql, s.SqlVars...) | ||||
| 	} else { | ||||
| 		s.db.Exec(sql[0]) | ||||
| 		s.SqlResult, s.Error = s.db.Exec(sql[0]) | ||||
| 	} | ||||
| 	return s | ||||
| } | ||||
|  | ||||
| @ -12,15 +12,16 @@ type User struct { | ||||
| } | ||||
| 
 | ||||
| func getDB() DB { | ||||
| 	db, _ := Open("postgres", "user=gorm dbname=gorm") | ||||
| 	db, _ := Open("postgres", "user=gorm dbname=gorm  sslmode=disable") | ||||
| 	return db | ||||
| } | ||||
| 
 | ||||
| func TestSaveAndFirst(t *testing.T) { | ||||
| 	db := getDB() | ||||
| 	u := &User{Name: "jinzhu"} | ||||
| 	fmt.Println("*******") | ||||
| 	fmt.Println(db.Save(u).Sql) | ||||
| 
 | ||||
| 	fmt.Println(db.Save(u).Error) | ||||
| 	fmt.Println(time.Now().String()) | ||||
| 
 | ||||
| 	user := &User{} | ||||
|  | ||||
							
								
								
									
										4
									
								
								sql.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								sql.go
									
									
									
									
									
								
							| @ -20,9 +20,9 @@ func (s *Orm) explain(value interface{}, operation string) { | ||||
| func (s *Orm) saveSql(value interface{}) { | ||||
| 	columns, values := modelValues(value) | ||||
| 	s.Sql = fmt.Sprintf( | ||||
| 		"INSERT INTO %v (%v) VALUES (%v)", | ||||
| 		"INSERT INTO \"%v\" (%v) VALUES (%v)", | ||||
| 		s.TableName, | ||||
| 		strings.Join(columns, ","), | ||||
| 		strings.Join(quoteMap(columns), ","), | ||||
| 		valuesToBinVar(values), | ||||
| 	) | ||||
| 	s.SqlVars = values | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu