From 53f0738dd23a9c84de0bcce6097a33bc9060f7a8 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 17 Feb 2022 23:22:14 -0500 Subject: dbstore/dbstore.go: update cpe queries, move queryIds outside of func --- dbstore/dbstore.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'dbstore') diff --git a/dbstore/dbstore.go b/dbstore/dbstore.go index 11ad02c..f432054 100644 --- a/dbstore/dbstore.go +++ b/dbstore/dbstore.go @@ -8,6 +8,7 @@ import ( "fmt" _ "github.com/mattn/go-sqlite3" "github.com/pablotron/cvez/cpedict" + "github.com/pablotron/cvez/cpematch" ) //go:embed sql @@ -104,6 +105,12 @@ func getQueries(ids []string) (map[string]string, error) { return r, nil } +var addCpeDictionaryQueryIds = []string { + "cpe/insert", + "cpe/insert-title", + "cpe/insert-ref", +} + // import CPE dictionary func (me DbStore) AddCpeDictionary(ctx context.Context, dict cpedict.Dictionary) error { // lazy-init db @@ -112,8 +119,7 @@ func (me DbStore) AddCpeDictionary(ctx context.Context, dict cpedict.Dictionary) } // build query map - queryIds := []string { "insert-cpe", "insert-title", "insert-ref" } - queries, err := getQueries(queryIds) + queries, err := getQueries(addCpeDictionaryQueryIds) if err != nil { return err } @@ -138,7 +144,7 @@ func (me DbStore) AddCpeDictionary(ctx context.Context, dict cpedict.Dictionary) // add items for _, item := range(dict.Items) { // add cpe - rs, err := sts["insert-cpe"].ExecContext(ctx, item.CpeUri, item.Cpe23Item.Name) + rs, err := sts["cpe/insert"].ExecContext(ctx, item.CpeUri, item.Cpe23Item.Name) if err != nil { return err } @@ -151,7 +157,7 @@ func (me DbStore) AddCpeDictionary(ctx context.Context, dict cpedict.Dictionary) // add titles for _, title := range(item.Titles) { - _, err := sts["insert-title"].ExecContext(ctx, id, title.Lang, title.Text) + _, err := sts["cpe/insert-title"].ExecContext(ctx, id, title.Lang, title.Text) if err != nil { return err } @@ -159,7 +165,7 @@ func (me DbStore) AddCpeDictionary(ctx context.Context, dict cpedict.Dictionary) // add refs for _, ref := range(item.References) { - _, err := sts["insert-ref"].ExecContext(ctx, id, ref.Href, ref.Text) + _, err := sts["cpe/insert-ref"].ExecContext(ctx, id, ref.Href, ref.Text) if err != nil { return err } -- cgit v1.2.3