github.com/quay/claircore@v1.5.28/test/postgres/package.go (about) 1 package postgres 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/jackc/pgx/v4/pgxpool" 8 9 "github.com/quay/claircore" 10 ) 11 12 // InsertUniquePackages inserts each unique package into the database. Nested distribution and source packages 13 // are un nested and inserted. The pkgs array should be created by a call to GenUniquePackages 14 func InsertPackages(ctx context.Context, pool *pgxpool.Pool, pkgs []*claircore.Package) error { 15 for _, pkg := range pkgs { 16 // index source packages 17 _, err := pool.Exec(ctx, `INSERT INTO package (id, kind, name, version, module, arch) VALUES ($1, $2, $3, $4, $5, $6)`, 18 &pkg.Source.ID, &pkg.Source.Kind, &pkg.Source.Name, &pkg.Source.Version, &pkg.Source.Module, &pkg.Source.Arch) 19 if err != nil { 20 return fmt.Errorf("failed to index test package's source %v: %v", pkg.Source, err) 21 } 22 23 // index package 24 _, err = pool.Exec(ctx, `INSERT INTO package (id, kind, name, version, module, arch) VALUES ($1, $2, $3, $4, $5, $6)`, 25 &pkg.ID, &pkg.Kind, &pkg.Name, &pkg.Version, &pkg.Module, &pkg.Arch) 26 if err != nil { 27 return fmt.Errorf("failed to insert test package %v: %v", pkg, err) 28 } 29 } 30 31 return nil 32 }