diff --git a/backend/internal/entity/certificateauthority/entity_test.go b/backend/internal/entity/certificateauthority/entity_test.go index 9568edc..90ae394 100644 --- a/backend/internal/entity/certificateauthority/entity_test.go +++ b/backend/internal/entity/certificateauthority/entity_test.go @@ -122,12 +122,12 @@ func (s *testsuite) TestList() { defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener")) s.mock. - ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "certificate_authority" WHERE name LIKE $1 AND "certificate_authority"."is_deleted" = $2`)). + ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"certificate_authority\" WHERE `certificate_authority`.`name` LIKE $1 AND \"certificate_authority\".\"is_deleted\" = $2")). WithArgs("%test%", 0). WillReturnRows(s.listCountRows) s.mock. - ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "certificate_authority" WHERE name LIKE $1 AND "certificate_authority"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)). + 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")). WithArgs("%test%", 0, 8). WillReturnRows(s.listRows) diff --git a/backend/internal/entity/dnsprovider/entity_test.go b/backend/internal/entity/dnsprovider/entity_test.go index 1a7a8bb..c8e7b46 100644 --- a/backend/internal/entity/dnsprovider/entity_test.go +++ b/backend/internal/entity/dnsprovider/entity_test.go @@ -204,12 +204,12 @@ func (s *testsuite) TestList() { defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener")) s.mock. - ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "dns_provider" WHERE acmesh_name LIKE $1 AND "dns_provider"."is_deleted" = $2`)). + ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"dns_provider\" WHERE `dns_provider`.`acmesh_name` LIKE $1 AND \"dns_provider\".\"is_deleted\" = $2")). WithArgs("dns%", 0). WillReturnRows(s.listCountRows) s.mock. - ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "dns_provider" WHERE acmesh_name LIKE $1 AND "dns_provider"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)). + 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")). WithArgs("dns%", 0, 8). WillReturnRows(s.listRows) diff --git a/backend/internal/entity/user/entity_test.go b/backend/internal/entity/user/entity_test.go index eae49d5..772b05a 100644 --- a/backend/internal/entity/user/entity_test.go +++ b/backend/internal/entity/user/entity_test.go @@ -307,12 +307,12 @@ func (s *testsuite) TestList() { defer goleak.VerifyNone(s.T(), goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener")) s.mock. - ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "user" WHERE name LIKE $1 AND "user"."is_deleted" = $2`)). + ExpectQuery(regexp.QuoteMeta("SELECT count(*) FROM \"user\" WHERE `user`.`name` LIKE $1 AND \"user\".\"is_deleted\" = $2")). WithArgs("%jon%", 0). WillReturnRows(s.listCountRows) s.mock. - ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "user" WHERE name LIKE $1 AND "user"."is_deleted" = $2 ORDER BY name asc LIMIT $3`)). + ExpectQuery(regexp.QuoteMeta("SELECT * FROM \"user\" WHERE `user`.`name` LIKE $1 AND \"user\".\"is_deleted\" = $2 ORDER BY name asc LIMIT $3")). WithArgs("%jon%", 0, 8). WillReturnRows(s.listRows) diff --git a/backend/internal/entity/user/methods.go b/backend/internal/entity/user/methods.go index d37b923..85b2ac0 100644 --- a/backend/internal/entity/user/methods.go +++ b/backend/internal/entity/user/methods.go @@ -86,7 +86,6 @@ func List(pageInfo model.PageInfo, filters []model.Filter, expand []string) (ent // DeleteAll will do just that, and should only be used for testing purposes. func DeleteAll() error { db := database.GetDB() - // nolint errcheck result := db.Exec(fmt.Sprintf(`DELETE FROM %s WHERE is_system = ?`, database.QuoteTableName("user")), false) return result.Error } diff --git a/backend/internal/tags/filters.go b/backend/internal/tags/filters.go index f17ff41..bd33ad5 100644 --- a/backend/internal/tags/filters.go +++ b/backend/internal/tags/filters.go @@ -6,6 +6,7 @@ import ( "regexp" "strings" + "npm/internal/database" "npm/internal/logger" "npm/internal/model" "npm/internal/util" @@ -33,8 +34,8 @@ func GetFilterMap(m interface{}, globalTablePrefix string) map[string]model.Filt n := tableNameFunc.Func.Call([]reflect.Value{v}) if len(n) > 0 { globalTablePrefix = fmt.Sprintf( - `"%s".`, - n[0].String(), + `%s.`, + database.QuoteTableName(n[0].String()), ) } } @@ -82,10 +83,10 @@ func GetFilterMap(m interface{}, globalTablePrefix string) map[string]model.Filt } // db can have many parts, we need to pull out the "column:value" part - f.Field = field.Name + f.Field = database.QuoteTableName(field.Name) r := regexp.MustCompile(`(?:^|;)column:([^;|$]+)(?:$|;)`) if matches := r.FindStringSubmatch(dbTag); len(matches) > 1 { - f.Field = fmt.Sprintf("%s%s", tablePrefix, matches[1]) + f.Field = fmt.Sprintf("%s%s", tablePrefix, database.QuoteTableName(matches[1])) } } filterMap[parts[0]] = f diff --git a/backend/scripts/lint.sh b/backend/scripts/lint.sh index 8abeeb3..44961b0 100755 --- a/backend/scripts/lint.sh +++ b/backend/scripts/lint.sh @@ -14,6 +14,7 @@ if [[ -n "$INCOMPLETE_COMMENTS" ]]; then # RESULT=1 fi +echo -e "${YELLOW}golangci-lint ...${RESET}" if ! golangci-lint run -E goimports ./...; then exit 1 fi