aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-17 23:22:14 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-17 23:22:14 -0500
commit53f0738dd23a9c84de0bcce6097a33bc9060f7a8 (patch)
tree445bca9389a595cf8df23aee3f78e0c00ce82dc5
parent9318627ab8acabed69d525f7b45f5f3d54c2e673 (diff)
downloadcvez-53f0738dd23a9c84de0bcce6097a33bc9060f7a8.tar.bz2
cvez-53f0738dd23a9c84de0bcce6097a33bc9060f7a8.zip
dbstore/dbstore.go: update cpe queries, move queryIds outside of func
-rw-r--r--dbstore/dbstore.go16
1 files changed, 11 insertions, 5 deletions
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
}