Don't quote table names

This commit is contained in:
Jinzhu 2013-11-03 21:19:38 +08:00
parent 63a9e5e3ae
commit 0c4e43cd7a
3 changed files with 6 additions and 4 deletions

View File

@ -147,7 +147,7 @@ db.Where("name <> ?", "jinzhu").Find(&users)
//// SELECT * FROM users WHERE name <> 'jinzhu';
// IN
db.Where("name in (?)", []string["jinzhu", "jinzhu 2"]).Find(&users)
db.Where("name in (?)", []string{"jinzhu", "jinzhu 2"}).Find(&users)
//// SELECT * FROM users WHERE name IN ('jinzhu', 'jinzhu 2');
// LIKE

6
do.go
View File

@ -106,7 +106,7 @@ func (s *Do) prepareCreateSql() {
}
s.sql = fmt.Sprintf(
"INSERT INTO \"%v\" (%v) VALUES (%v) %v",
"INSERT INTO %v (%v) VALUES (%v) %v",
s.tableName(),
strings.Join(columns, ","),
strings.Join(sqls, ","),
@ -616,7 +616,7 @@ func (s *Do) createTable() *Do {
}
s.sql = fmt.Sprintf(
"CREATE TABLE \"%v\" (%v)",
"CREATE TABLE %v (%v)",
s.tableName(),
strings.Join(sqls, ","),
)
@ -625,7 +625,7 @@ func (s *Do) createTable() *Do {
func (s *Do) dropTable() *Do {
s.sql = fmt.Sprintf(
"DROP TABLE \"%v\"",
"DROP TABLE %v",
s.tableName(),
)
return s

View File

@ -1099,4 +1099,6 @@ func TestForReadme(t *testing.T) {
}
db.Save(&user)
var users []User
db.Where("name in (?)", []string{"jinzhu", "jinzhu 2"}).Find(&users)
}