github.com/quay/claircore@v1.5.28/test/postgres/scanner.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/indexer" 10 ) 11 12 // InsertUniqueScanners inserts each unique scanner into the database. the scanner's primary key (int) is set 13 // to the index of the scanner in the array. 14 func InsertUniqueScanners(ctx context.Context, pool *pgxpool.Pool, scnrs indexer.VersionedScanners) error { 15 for i, scnr := range scnrs { 16 _, err := pool.Exec(ctx, `INSERT INTO scanner (id, kind, name, version) VALUES ($1, $2, $3, $4);`, 17 i, scnr.Kind(), scnr.Name(), scnr.Version()) 18 if err != nil { 19 return fmt.Errorf("failed to insert test scanner: %v", err) 20 } 21 } 22 return nil 23 }