Skip to content

Commit e78dd06

Browse files
committed
Quote filter fields
1 parent 9a2e5c9 commit e78dd06

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

backend/internal/entity/certificateauthority/entity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ func (s *testsuite) TestList() {
122122
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
123123

124124
s.mock.
125-
ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "certificate_authority" WHERE name LIKE $1 AND "certificate_authority"."is_deleted" = $2`)).
125+
ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"certificate_authority\" WHERE `certificate_authority`.`name` LIKE $1 AND \"certificate_authority\".\"is_deleted\" = $2")).
126126
WithArgs("%test%", 0).
127127
WillReturnRows(s.listCountRows)
128128

129129
s.mock.
130-
ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "certificate_authority" WHERE name LIKE $1 AND "certificate_authority"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)).
130+
ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"certificate_authority\" WHERE `certificate_authority`.`name` LIKE $1 AND \"certificate_authority\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")).
131131
WithArgs("%test%", 0, 8).
132132
WillReturnRows(s.listRows)
133133

backend/internal/entity/dnsprovider/entity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ func (s *testsuite) TestList() {
204204
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
205205

206206
s.mock.
207-
ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "dns_provider" WHERE acmesh_name LIKE $1 AND "dns_provider"."is_deleted" = $2`)).
207+
ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"dns_provider\" WHERE `dns_provider`.`acmesh_name` LIKE $1 AND \"dns_provider\".\"is_deleted\" = $2")).
208208
WithArgs("dns%", 0).
209209
WillReturnRows(s.listCountRows)
210210

211211
s.mock.
212-
ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "dns_provider" WHERE acmesh_name LIKE $1 AND "dns_provider"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)).
212+
ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"dns_provider\" WHERE `dns_provider`.`acmesh_name` LIKE $1 AND \"dns_provider\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")).
213213
WithArgs("dns%", 0, 8).
214214
WillReturnRows(s.listRows)
215215

backend/internal/entity/user/entity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ func (s *testsuite) TestList() {
307307
defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
308308

309309
s.mock.
310-
ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "user" WHERE name LIKE $1 AND "user"."is_deleted" = $2`)).
310+
ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"user\" WHERE `user`.`name` LIKE $1 AND \"user\".\"is_deleted\" = $2")).
311311
WithArgs("%jon%", 0).
312312
WillReturnRows(s.listCountRows)
313313

314314
s.mock.
315-
ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "user" WHERE name LIKE $1 AND "user"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)).
315+
ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"user\" WHERE `user`.`name` LIKE $1 AND \"user\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")).
316316
WithArgs("%jon%", 0, 8).
317317
WillReturnRows(s.listRows)
318318

backend/internal/entity/user/methods.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent
8686
// DeleteAll will do just that, and should only be used for testing purposes.
8787
func DeleteAll() error {
8888
db := database.GetDB()
89-
// nolint errcheck
9089
result := db.Exec(fmt.Sprintf(`DELETE FROM %s WHERE is_system = ?`, database.QuoteTableName("user")), false)
9190
return result.Error
9291
}

backend/internal/tags/filters.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"regexp"
77
"strings"
88

9+
"npm/internal/database"
910
"npm/internal/logger"
1011
"npm/internal/model"
1112
"npm/internal/util"
@@ -33,8 +34,8 @@ func GetFilterMap(m interface{}, globalTablePrefix string) map[string]model.Filt
3334
n := tableNameFunc.Func.Call([]reflect.Value{v})
3435
if len(n) > 0 {
3536
globalTablePrefix = fmt.Sprintf(
36-
`"%s".`,
37-
n[0].String(),
37+
`%s.`,
38+
database.QuoteTableName(n[0].String()),
3839
)
3940
}
4041
}
@@ -82,10 +83,10 @@ func GetFilterMap(m interface{}, globalTablePrefix string) map[string]model.Filt
8283
}
8384

8485
// db can have many parts, we need to pull out the "column:value" part
85-
f.Field = field.Name
86+
f.Field = database.QuoteTableName(field.Name)
8687
r := regexp.MustCompile(`(?:^|;)column:([^;|$]+)(?:$|;)`)
8788
if matches := r.FindStringSubmatch(dbTag); len(matches) > 1 {
88-
f.Field = fmt.Sprintf("%s%s", tablePrefix, matches[1])
89+
f.Field = fmt.Sprintf("%s%s", tablePrefix, database.QuoteTableName(matches[1]))
8990
}
9091
}
9192
filterMap[parts[0]] = f

backend/scripts/lint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if [[ -n "$INCOMPLETE_COMMENTS" ]]; then
1414
# RESULT=1
1515
fi
1616

17+
echo -e "${YELLOW}golangci-lint ...${RESET}"
1718
if ! golangci-lint run -E goimports ./...; then
1819
exit 1
1920
fi

0 commit comments

Comments
 (0)