1
0
forked from Plemya-x/ALR

refactor: migrate repos find to struct

This commit is contained in:
2025-01-14 13:18:51 +03:00
parent 12d83f2015
commit e1829c4824
3 changed files with 40 additions and 38 deletions

View File

@ -15,7 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package repos
import (
@ -24,10 +23,7 @@ import (
"plemya-x.ru/alr/internal/db"
)
// FindPkgs looks for packages matching the inputs inside the database.
// It returns a map that maps the package name input to any packages found for it.
// It also returns a slice that contains the names of all packages that were not found.
func FindPkgs(ctx context.Context, pkgs []string) (map[string][]db.Package, []string, error) {
func (rs *Repos) FindPkgs(ctx context.Context, pkgs []string) (map[string][]db.Package, []string, error) {
found := map[string][]db.Package{}
notFound := []string(nil)
@ -36,7 +32,7 @@ func FindPkgs(ctx context.Context, pkgs []string) (map[string][]db.Package, []st
continue
}
result, err := db.GetPkgs(ctx, "json_array_contains(provides, ?)", pkgName)
result, err := rs.db.GetPkgs(ctx, "json_array_contains(provides, ?)", pkgName)
if err != nil {
return nil, nil, err
}
@ -55,7 +51,7 @@ func FindPkgs(ctx context.Context, pkgs []string) (map[string][]db.Package, []st
result.Close()
if added == 0 {
result, err := db.GetPkgs(ctx, "name LIKE ?", pkgName)
result, err := rs.db.GetPkgs(ctx, "name LIKE ?", pkgName)
if err != nil {
return nil, nil, err
}