fix: support implicit table alias
This commit is contained in:
parent
1935eb0adb
commit
0fb5abcfd3
@ -55,7 +55,7 @@ func (db *DB) Clauses(conds ...clause.Expression) (tx *DB) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var tableRegexp = regexp.MustCompile(`(?i).+? AS (\w+)\s*(?:$|,)`)
|
var tableRegexp = regexp.MustCompile(`(?i).+?(?: AS )?(\w+)\s*(?:$|,)`)
|
||||||
|
|
||||||
// Table specify the table you would like to run db operations
|
// Table specify the table you would like to run db operations
|
||||||
//
|
//
|
||||||
|
@ -32,6 +32,11 @@ func TestTable(t *testing.T) {
|
|||||||
t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
|
t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r = dryDB.Table("user u").Select("name").Find(&User{}).Statement
|
||||||
|
if !regexp.MustCompile("SELECT .name. FROM user u WHERE .u.\\..deleted_at. IS NULL").MatchString(r.Statement.SQL.String()) {
|
||||||
|
t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
|
||||||
|
}
|
||||||
|
|
||||||
r = dryDB.Table("`people`").Table("`user`").Find(&User{}).Statement
|
r = dryDB.Table("`people`").Table("`user`").Find(&User{}).Statement
|
||||||
if !regexp.MustCompile("SELECT \\* FROM `user`").MatchString(r.Statement.SQL.String()) {
|
if !regexp.MustCompile("SELECT \\* FROM `user`").MatchString(r.Statement.SQL.String()) {
|
||||||
t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
|
t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user