Repository: go-gorm/gorm
Pull request #4616 (2021-08-16 07:11:37)

Bump gorm.io/gorm from 1.21.12 to 1.21.13 in /tests
Bumps [gorm.io/gorm](https://github.com/go-gorm/gorm) from 1.21.12 to 1.21.13.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/go-gorm/gorm/commit/2b2f6e77af28e57e7bbea5962d58b1a7cb8ff47b"><code>2b2f6e7</code></a> Add SchemaName to NamingStrategy</li>
<li><a href="https://github.com/go-gorm/gorm/commit/a83d25e25e700f8a3c40dda048ac52b23bba31d5"><code>a83d25e</code></a> chore(logger): explicitly set config of Default Logger (<a href="https://github-redirect.dependabot.com/go-gorm/gorm/issues/4605">#4605</a>)</li>
<li><a href="https://github.com/go-gorm/gorm/commit/21e85b89d68c3d9af5a7f23280471cff05dd2e8a"><code>21e85b8</code></a> Fix create with ignore migration (<a href="https://github-redirect.dependabot.com/go-gorm/gorm/issues/4571">#4571</a>)</li>
<li><a href="https://github.com/go-gorm/gorm/commit/82fe81530305257eb13f708d8fe5bd63c05cac01"><code>82fe815</code></a> fix: table couln't be reentrant (<a href="https://github-redirect.dependabot.com/go-gorm/gorm/issues/4556">#4556</a>)</li>
<li><a href="https://github.com/go-gorm/gorm/commit/cbe72751ac7e900a86ca843757c677b3c322732b"><code>cbe7275</code></a> Update Dependencies  (<a href="https://github-redirect.dependabot.com/go-gorm/gorm/issues/4582">#4582</a>)</li>
<li><a href="https://github.com/go-gorm/gorm/commit/a870486c4f967d732b2786f320886b0230053c18"><code>a870486</code></a> Do not emit ORDER BY for empty values (<a href="https://github-redirect.dependabot.com/go-gorm/gorm/issues/4592">#4592</a>)</li>
<li><a href="https://github.com/go-gorm/gorm/commit/9e5a4e30b4045ea663b8c03a57ddefd9673f2356"><code>9e5a4e3</code></a> Fix migrator GuessConstraintAndTable method for return value for *schema.Chec...</li>
<li><a href="https://github.com/go-gorm/gorm/commit/413fe587c643109206d72736377eb28dde6b9555"><code>413fe58</code></a> Optimize migrator.go MigrateColumn and ColumnTypes func. (<a href="https://github-redirect.dependabot.com/go-gorm/gorm/issues/4532">#4532</a>)</li>
<li><a href="https://github.com/go-gorm/gorm/commit/7a49629fd1c7c35bd76df5016cd4193bf3db7d81"><code>7a49629</code></a> optimize Parse func for fieldValue.Interface</li>
<li><a href="https://github.com/go-gorm/gorm/commit/41ac73b6a1e89e72e59b61b77815ee690af71fb8"><code>41ac73b</code></a> update comment for ConvertSliceOfMapToValuesForCreate func</li>
<li>Additional commits viewable in <a href="https://github.com/go-gorm/gorm/compare/v1.21.12...v1.21.13">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=gorm.io/gorm&package-manager=go_modules&previous-version=1.21.12&new-version=1.21.13)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/finisher_api.go b/finisher_api.go
index 537c955..34e1596 100644
--- a/finisher_api.go
+++ b/finisher_api.go
@@ -390,7 +390,7 @@ func (db *DB) Count(count *int64) (tx *DB) {
 		if len(tx.Statement.Selects) == 1 {
 			dbName := tx.Statement.Selects[0]
 			fields := strings.FieldsFunc(dbName, utils.IsValidDBNameChar)
-			if len(fields) == 1 || (len(fields) == 3 && strings.ToUpper(fields[1]) == "AS") {
+			if len(fields) == 1 || (len(fields) == 3 && (strings.ToUpper(fields[1]) == "AS" || fields[1] == ".")) {
 				if tx.Statement.Parse(tx.Statement.Model) == nil {
 					if f := tx.Statement.Schema.LookUpField(dbName); f != nil {
 						dbName = f.DBName
diff --git a/statement.go b/statement.go
index 8b682c8..93b78c1 100644
--- a/statement.go
+++ b/statement.go
@@ -129,6 +129,8 @@ func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) {
 			stmt.QuoteTo(writer, d)
 		}
 		writer.WriteByte(')')
+	case clause.Expr:
+		v.Build(stmt)
 	case string:
 		stmt.DB.Dialector.QuoteTo(writer, v)
 	case []string:


Test patch:
diff --git a/clause/expression_test.go b/clause/expression_test.go
index 0ccd077..0507486 100644
--- a/clause/expression_test.go
+++ b/clause/expression_test.go
@@ -156,6 +156,18 @@ func TestExpression(t *testing.T) {
 		},
 		ExpectedVars: []interface{}{"a", "b"},
 		Result:       "`column-name` NOT IN (?,?)",
+	}, {
+		Expressions: []clause.Expression{
+			clause.Eq{Column: clause.Expr{SQL: "SUM(?)", Vars: []interface{}{clause.Column{Name: "id"}}}, Value: 100},
+		},
+		ExpectedVars: []interface{}{100},
+		Result:       "SUM(`id`) = ?",
+	}, {
+		Expressions: []clause.Expression{
+			clause.Gte{Column: clause.Expr{SQL: "SUM(?)", Vars: []interface{}{clause.Column{Table: "users", Name: "id"}}}, Value: 100},
+		},
+		ExpectedVars: []interface{}{100},
+		Result:       "SUM(`users`.`id`) >= ?",
 	}}
 
 	for idx, result := range results {
diff --git a/tests/go.mod b/tests/go.mod
index b623b36..c456cc9 100644
--- a/tests/go.mod
+++ b/tests/go.mod
@@ -10,7 +10,7 @@ require (
 	gorm.io/driver/postgres v1.1.0
 	gorm.io/driver/sqlite v1.1.4
 	gorm.io/driver/sqlserver v1.0.7
-	gorm.io/gorm v1.21.12
+	gorm.io/gorm v1.21.13
 )
 
 replace gorm.io/gorm => ../