From 832bedda0f93a298462941d29655b66a25020ee1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 09:42:15 +0900 Subject: [PATCH] Bump github.com/go-rel/mysql from 0.12.0 to 0.13.0 (#114) Bumps [github.com/go-rel/mysql](https://github.com/go-rel/mysql) from 0.12.0 to 0.13.0. - [Release notes](https://github.com/go-rel/mysql/releases) - [Changelog](https://github.com/go-rel/mysql/blob/main/.goreleaser.yml) - [Commits](https://github.com/go-rel/mysql/compare/v0.12.0...v0.13.0) --- updated-dependencies: - dependency-name: github.com/go-rel/mysql dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 +-- go.sum | 8 ++--- .../github.com/go-rel/sql/builder/buffer.go | 35 +++++++++++++------ vendor/github.com/go-rel/sql/builder/query.go | 18 ++++------ vendor/modules.txt | 4 +-- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index cfb8ec04..0d85fe2a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-contrib/requestid v1.0.2 github.com/gin-contrib/zap v1.1.3 github.com/gin-gonic/gin v1.10.0 - github.com/go-rel/mysql v0.12.0 + github.com/go-rel/mysql v0.13.0 github.com/go-rel/rel v0.42.0 github.com/go-rel/reltest v0.12.0 github.com/go-sql-driver/mysql v1.8.1 @@ -27,7 +27,7 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect - github.com/go-rel/sql v0.16.0 // indirect + github.com/go-rel/sql v0.17.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/go.sum b/go.sum index dd3e80c1..e96fa960 100644 --- a/go.sum +++ b/go.sum @@ -31,15 +31,15 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/go-rel/mysql v0.12.0 h1:GMwNktroIgA5a8AMxSj6MnnobXqZ85LnjPjtV0OU3Pc= -github.com/go-rel/mysql v0.12.0/go.mod h1:Q1Xa47BIyoeDfv5nFXo6VCEWwjpWpOX5wJnUAYOz4HA= +github.com/go-rel/mysql v0.13.0 h1:8L4LI8VNTzpxINe1hn0oUMuPawzynGXbhPuFaXyQx0w= +github.com/go-rel/mysql v0.13.0/go.mod h1:sJXJfcMGMNLSn+1pySMfaPMKpdFLp6Z7V2l48G74IJQ= github.com/go-rel/primaryreplica v0.6.0 h1:8ZlgUatz+Ger+d51aIvlDWK3iZSa2RwD6ys3cingyf0= github.com/go-rel/rel v0.42.0 h1:LxtI/Q7ConrivN+rp95LvLnu7QWU0stD9/ZpeR6OdrU= github.com/go-rel/rel v0.42.0/go.mod h1:7RaEaNz30kCt/14m4VgdVWXFzATWnqJ40f0z1DnAUyk= github.com/go-rel/reltest v0.12.0 h1:8tP6zeH22mOwbfDbtQ6pn7UgxVK8D1XgkAn31YQ8W/o= github.com/go-rel/reltest v0.12.0/go.mod h1:JQGeMVG8i3OTk7wxNxKfrg1DyNz+nJcB0bjlyUjL4dE= -github.com/go-rel/sql v0.16.0 h1:6k+eYAMSwBsKFXLHQFpPplMjWQJf6DMUPlTxwWoR/l8= -github.com/go-rel/sql v0.16.0/go.mod h1:jPTiMPVdiNqsNnho1g7daKXW8cofViB/gcGXlMdNBac= +github.com/go-rel/sql v0.17.0 h1:ldwI7ctxEAmXb1Dy0AiECbAPAkT43NEImzUjMdGPVlo= +github.com/go-rel/sql v0.17.0/go.mod h1:JxiiqL4lOcK+/2UBYuGnQewBCYe2BptCcRQuhHFcv5o= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= diff --git a/vendor/github.com/go-rel/sql/builder/buffer.go b/vendor/github.com/go-rel/sql/builder/buffer.go index e807a62d..1f76e1a0 100644 --- a/vendor/github.com/go-rel/sql/builder/buffer.go +++ b/vendor/github.com/go-rel/sql/builder/buffer.go @@ -131,10 +131,15 @@ func (b Buffer) escape(table, value string) string { return escapedValue.(string) } - var escaped_table string + table, alias := extractAlias(table) + var escapedTable string if table != "" { - if i := strings.Index(strings.ToLower(table), " as "); i > -1 { - return b.escape(table[:i], "") + " AS " + b.Quoter.ID(table[i+4:]) + if table != alias { + if value == "" { + return b.escape(table, "") + " AS " + b.Quoter.ID(alias) + } else { + escapedTable = b.Quoter.ID(alias) + } } if b.AllowTableSchema && strings.IndexByte(table, '.') >= 0 { parts := strings.Split(table, ".") @@ -142,24 +147,24 @@ func (b Buffer) escape(table, value string) string { part = strings.TrimSpace(part) parts[i] = b.Quoter.ID(part) } - escaped_table = strings.Join(parts, ".") + escapedTable = strings.Join(parts, ".") } else { - escaped_table = b.Quoter.ID(strings.ReplaceAll(table, ".", "_")) + escapedTable = b.Quoter.ID(strings.ReplaceAll(table, ".", "_")) } } if value == "" { - escapedValue = escaped_table + escapedValue = escapedTable } else if value == "*" { - escapedValue = escaped_table + ".*" + escapedValue = escapedTable + ".*" } else if len(value) > 0 && value[0] == UnescapeCharacter { escapedValue = value[1:] } else if _, err := strconv.Atoi(value); err == nil { escapedValue = value } else if i := strings.Index(strings.ToLower(value), " as "); i > -1 { - escapedValue = b.escape(table, value[:i]) + " AS " + b.Quoter.ID(value[i+4:]) + escapedValue = b.escape(alias, value[:i]) + " AS " + b.Quoter.ID(value[i+4:]) } else if start, end := strings.IndexRune(value, '('), strings.IndexRune(value, ')'); start >= 0 && end >= 0 && end > start { - escapedValue = value[:start+1] + b.escape(table, value[start+1:end]) + value[end:] + escapedValue = value[:start+1] + b.escape(alias, value[start+1:end]) + value[end:] } else { parts := strings.Split(value, ".") for i, part := range parts { @@ -171,7 +176,7 @@ func (b Buffer) escape(table, value string) string { } result := strings.Join(parts, ".") if len(parts) == 1 && table != "" { - result = escaped_table + "." + result + result = escapedTable + "." + result } escapedValue = result } @@ -228,3 +233,13 @@ func (bf BufferFactory) Create() Buffer { BoolFalseValue: bf.BoolFalseValue, } } + +// extract alias in the form of table as alias +// if no alias, table will be returned as alias +func extractAlias(input string) (string, string) { + if i := strings.Index(strings.ToLower(input), " as "); i > -1 { + return input[:i], input[i+4:] + } + + return input, input +} diff --git a/vendor/github.com/go-rel/sql/builder/query.go b/vendor/github.com/go-rel/sql/builder/query.go index a8136c54..001c3f31 100644 --- a/vendor/github.com/go-rel/sql/builder/query.go +++ b/vendor/github.com/go-rel/sql/builder/query.go @@ -105,20 +105,16 @@ func (q Query) WriteJoin(buffer *Buffer, table string, joins []rel.JoinQuery) { for _, join := range joins { var ( - from = join.From - to = join.To + _, sAlias = extractAlias(table) + jTable, jAlias = extractAlias(join.Table) + from = join.From + to = join.To ) - jtable := join.Table - // If join table has alias use that for filter conditions - if i := strings.Index(strings.ToLower(jtable), " as "); i > -1 { - jtable = jtable[i+4:] - } - // TODO: move this to core functionality, and infer join condition using assoc data. if join.Arguments == nil && (join.From == "" || join.To == "") { - from = table + "." + strings.TrimSuffix(join.Table, "s") + "_id" - to = jtable + ".id" + from = sAlias + "." + strings.TrimSuffix(jTable, "s") + "_id" + to = jAlias + ".id" } buffer.WriteByte(' ') @@ -133,7 +129,7 @@ func (q Query) WriteJoin(buffer *Buffer, table string, joins []rel.JoinQuery) { buffer.WriteEscape(to) if !join.Filter.None() { buffer.WriteString(" AND ") - q.Filter.Write(buffer, jtable, join.Filter, q) + q.Filter.Write(buffer, join.Table, join.Filter, q) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 56f81c88..30ccb558 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -74,7 +74,7 @@ github.com/go-playground/universal-translator # github.com/go-playground/validator/v10 v10.20.0 ## explicit; go 1.18 github.com/go-playground/validator/v10 -# github.com/go-rel/mysql v0.12.0 +# github.com/go-rel/mysql v0.13.0 ## explicit; go 1.21 github.com/go-rel/mysql # github.com/go-rel/rel v0.42.0 @@ -84,7 +84,7 @@ github.com/go-rel/rel/where # github.com/go-rel/reltest v0.12.0 ## explicit; go 1.21 github.com/go-rel/reltest -# github.com/go-rel/sql v0.16.0 +# github.com/go-rel/sql v0.17.0 ## explicit; go 1.21 github.com/go-rel/sql github.com/go-rel/sql/builder