Skip to content

Commit

Permalink
available-values-inserting-db
Browse files Browse the repository at this point in the history
  • Loading branch information
an1l4 committed Nov 8, 2023
1 parent 5af755c commit 4a0a60a
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions client/pkg/clickhouse/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,12 @@ func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) {
func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
log.Println("####started inserting value")
result := metrics.Report
var (
tx, _ = c.conn.Begin()
stmt, _ = tx.Prepare(InsertTrivySbom)
)

if result.CycloneDX != nil {
var (
tx, _ = c.conn.Begin()
stmt, _ = tx.Prepare(InsertTrivySbom)
)
if _,err:= stmt.Exec(
metrics.ID,
result.CycloneDX.Metadata.Component.Name,
Expand All @@ -621,29 +622,15 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
); err!=nil {
log.Fatal(err)
}

}else {
if _,err:= stmt.Exec(
metrics.ID,
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
); err!=nil {
if err:=tx.Commit();err!=nil {
log.Fatal(err)
}
stmt.Close()
}else {
log.Println("No Data Available")

}

if err:=tx.Commit();err!=nil {
log.Fatal(err)
}
stmt.Close()

}
func (c *DBClient) Close() {
_ = c.conn.Close()
Expand Down

0 comments on commit 4a0a60a

Please sign in to comment.