diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-18 20:57:40 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-18 20:57:40 -0500 |
commit | d1483e75727afccc251f70f5a58e756efaff8b9e (patch) | |
tree | 4ade0479bf39ca470b24e9e482f118ff24845a21 /dbstore/sqlfs.go | |
parent | 262479663d607966fadc06ee44c6191d0dce88ed (diff) | |
download | cvez-d1483e75727afccc251f70f5a58e756efaff8b9e.tar.bz2 cvez-d1483e75727afccc251f70f5a58e756efaff8b9e.zip |
dbstore: refactor sqlfs and tx, add tx tests
Diffstat (limited to 'dbstore/sqlfs.go')
-rw-r--r-- | dbstore/sqlfs.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/dbstore/sqlfs.go b/dbstore/sqlfs.go new file mode 100644 index 0000000..99626a2 --- /dev/null +++ b/dbstore/sqlfs.go @@ -0,0 +1,38 @@ +package dbstore + +import ( + "embed" + "fmt" +) + +//go:embed sql +var sqlFs embed.FS + +// Get single query from embedded sqlFs. +func getQuery(id string) (string, error) { + // read query + if data, err := sqlFs.ReadFile(fmt.Sprintf("sql/%s.sql", id)); err != nil { + return "", err + } else { + // return query + return string(data), nil + } +} + +// Return queries from embedded sqlFs and return map of query ID to SQL. +func getQueries(ids []string) (map[string]string, error) { + r := make(map[string]string) + + for _, id := range(ids) { + // read query + if sql, err := getQuery(id); err != nil { + return r, fmt.Errorf("%s: %s", id, err.Error()) + } else { + // save query + r[id] = sql + } + } + + // return success + return r, nil +} |