Skip to content

Commit 4a0a60a

Browse files
committed
available-values-inserting-db
1 parent 5af755c commit 4a0a60a

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

client/pkg/clickhouse/db_client.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,12 @@ func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) {
603603
func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
604604
log.Println("####started inserting value")
605605
result := metrics.Report
606-
var (
607-
tx, _ = c.conn.Begin()
608-
stmt, _ = tx.Prepare(InsertTrivySbom)
609-
)
606+
610607
if result.CycloneDX != nil {
608+
var (
609+
tx, _ = c.conn.Begin()
610+
stmt, _ = tx.Prepare(InsertTrivySbom)
611+
)
611612
if _,err:= stmt.Exec(
612613
metrics.ID,
613614
result.CycloneDX.Metadata.Component.Name,
@@ -621,29 +622,15 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
621622
); err!=nil {
622623
log.Fatal(err)
623624
}
624-
625-
}else {
626-
if _,err:= stmt.Exec(
627-
metrics.ID,
628-
"-",
629-
"-",
630-
"-",
631-
"-",
632-
"-",
633-
"-",
634-
"-",
635-
"-",
636-
); err!=nil {
625+
if err:=tx.Commit();err!=nil {
637626
log.Fatal(err)
638627
}
628+
stmt.Close()
629+
}else {
630+
log.Println("No Data Available")
639631

640632
}
641633

642-
if err:=tx.Commit();err!=nil {
643-
log.Fatal(err)
644-
}
645-
stmt.Close()
646-
647634
}
648635
func (c *DBClient) Close() {
649636
_ = c.conn.Close()

0 commit comments

Comments
 (0)