@@ -19,7 +19,6 @@ import (
1919 "database/sql"
2020 "fmt"
2121
22- "github.com/nephio-project/porch/api/porch/v1alpha1"
2322 cachetypes "github.com/nephio-project/porch/pkg/cache/types"
2423 "github.com/nephio-project/porch/pkg/repository"
2524 "go.opentelemetry.io/otel/trace"
@@ -97,7 +96,7 @@ func pkgRevReadFromDB(ctx context.Context, prk repository.PackageRevisionKey, re
9796}
9897
9998func pkgRevListPRsFromDB (ctx context.Context , filter repository.ListPackageRevisionFilter ) ([]* dbPackageRevision , error ) {
100- _ , span := tracer .Start (ctx , "dbrepositorysql::repoDeleteFromDB " , trace .WithAttributes ())
99+ _ , span := tracer .Start (ctx , "dbrepositorysql::pkgRevListPRsFromDB " , trace .WithAttributes ())
101100 defer span .End ()
102101
103102 klog .V (5 ).Infof ("pkgRevListPRsFromDB: listing package revisions for filter %+v" , filter )
@@ -444,94 +443,3 @@ func pkgRevDeleteFromDB(ctx context.Context, prk repository.PackageRevisionKey)
444443
445444 return err
446445}
447-
448- func prListFilter2WhereClause (filter repository.ListPackageRevisionFilter ) string {
449- whereStatement := ""
450-
451- repoKey := filter .Key .RKey ()
452- whereStatement , first := prListFilter2SubClauseStr (whereStatement , repoKey .Namespace , "repositories.k8s_name_space" , true )
453- whereStatement , first = prListFilter2SubClauseStr (whereStatement , repoKey .Name , "repositories.k8s_name" , first )
454- whereStatement , first = prListFilter2SubClauseStr (whereStatement , repoKey .Path , "repositories.directory" , first )
455- whereStatement , first = prListFilter2SubClauseStr (whereStatement , repoKey .PlaceholderWSname , "repositories.default_ws_name" , first )
456-
457- pkgKey := filter .Key .PKey ()
458- whereStatement , first = prListFilter2SubClauseStr (whereStatement , pkgKey .K8SName (), "packages.k8s_name" , first )
459- whereStatement , first = prListFilter2SubClauseStr (whereStatement , pkgKey .Path , "packages.package_path" , first )
460-
461- prKey := filter .Key
462- whereStatement , first = prListFilter2SubClauseStr (whereStatement , prKey .K8SName (), "package_revisions.k8s_name" , first )
463- whereStatement , first = prListFilter2SubClauseInt (whereStatement , prKey .Revision , "package_revisions.revision" , first )
464- whereStatement , first = prListFilter2SubClauseWorkspace (whereStatement , prKey .WorkspaceName , "package_revisions.k8s_name" , first )
465-
466- whereStatement , _ = prListFilter2SubClauseLifecycle (whereStatement , filter .Lifecycles , "package_revisions.lifecycle" , first )
467-
468- if whereStatement == "" {
469- return whereStatement
470- } else {
471- return "WHERE\n " + whereStatement
472- }
473- }
474-
475- func prListFilter2SubClauseStr (whereStatement , filterField , column string , first bool ) (string , bool ) {
476- if filterField == "" {
477- return whereStatement , first
478- }
479-
480- subClause := fmt .Sprintf ("%s='%s'\n " , column , filterField )
481-
482- if first {
483- return whereStatement + subClause , false
484- } else {
485- return whereStatement + "AND " + subClause , false
486- }
487- }
488-
489- func prListFilter2SubClauseInt (whereStatement string , filterField int , column string , first bool ) (string , bool ) {
490- if filterField == 0 {
491- return whereStatement , first
492- }
493-
494- subClause := fmt .Sprintf ("%s=%d\n " , column , filterField )
495-
496- if first {
497- return whereStatement + subClause , false
498- } else {
499- return whereStatement + "AND " + subClause , false
500- }
501- }
502-
503- func prListFilter2SubClauseWorkspace (whereStatement string , filterField string , column string , first bool ) (string , bool ) {
504- if filterField == "" {
505- return whereStatement , first
506- }
507-
508- subClause := fmt .Sprintf ("%s LIKE '%%.%s'\n " , column , filterField )
509-
510- if first {
511- return whereStatement + subClause , false
512- } else {
513- return whereStatement + "AND " + subClause , false
514- }
515- }
516-
517- func prListFilter2SubClauseLifecycle (whereStatement string , filterField []v1alpha1.PackageRevisionLifecycle , column string , first bool ) (string , bool ) {
518- if len (filterField ) == 0 {
519- return whereStatement , first
520- }
521-
522- subClause := "("
523- for i , lifecycle := range filterField {
524- if i == 0 {
525- subClause = subClause + fmt .Sprintf ("%s='%s'" , column , lifecycle )
526- } else {
527- subClause = subClause + fmt .Sprintf (" OR %s='%s'" , column , lifecycle )
528- }
529- }
530- subClause += ")"
531-
532- if first {
533- return whereStatement + subClause , false
534- } else {
535- return whereStatement + "AND " + subClause , false
536- }
537- }
0 commit comments