-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add rpm list api * Use prepared statements * switch to embeded named params * move existing apis to new query * remove struct * add mock * address feedback
- Loading branch information
1 parent
c546e5d
commit 358a433
Showing
6 changed files
with
276 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package tangy | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/jackc/pgx/v5" | ||
"golang.org/x/exp/rand" | ||
) | ||
|
||
// contentIdsInVersion forms a single query to fetch a list of content ids in a repository version | ||
// | ||
// It uses randomized query parameter names and modifies the passed in namedArgs to include the key/values for these named query parameters. | ||
// By using randomized query parameter names, this query can be included multiple times with different repository | ||
// versions as multiple subqueries. | ||
func contentIdsInVersion(repoId string, versionNum int, namedArgs *pgx.NamedArgs) string { | ||
ran := rand.Int() | ||
repoIdName := fmt.Sprintf("%v%v", "repoName", ran) | ||
versionNumName := fmt.Sprintf("%v%v", "versionNum", ran) | ||
query := ` | ||
SELECT crc.content_id | ||
FROM core_repositorycontent crc | ||
INNER JOIN core_repositoryversion crv ON (crc.version_added_id = crv.pulp_id) | ||
LEFT OUTER JOIN core_repositoryversion crv2 ON (crc.version_removed_id = crv2.pulp_id) | ||
WHERE crv.repository_id = @%v AND crv.number <= @%v AND NOT (crv2.number <= @%v AND crv2.number IS NOT NULL) | ||
` | ||
(*namedArgs)[repoIdName] = repoId | ||
(*namedArgs)[versionNumName] = versionNum | ||
return fmt.Sprintf(query, repoIdName, versionNumName, versionNumName) | ||
} | ||
|
||
// Creates a sub query (including parenthesis) to lookup the content IDs of a list of repository versions. | ||
// | ||
// Takes in a pointer to Named args in order to add required named arguments for the query. Multiple queries are created | ||
// and UNION'd together | ||
func contentIdsInVersions(repoVerMap []ParsedRepoVersion, namedArgs *pgx.NamedArgs) string { | ||
queries := []string{} | ||
for _, parsed := range repoVerMap { | ||
queries = append(queries, contentIdsInVersion(parsed.RepositoryUUID, parsed.Version, namedArgs)) | ||
} | ||
return fmt.Sprintf("( %v ) ", strings.Join(queries, " UNION ")) | ||
} |
Oops, something went wrong.