aboutsummaryrefslogtreecommitdiff
path: root/dbstore/sqlfs.go
diff options
context:
space:
mode:
Diffstat (limited to 'dbstore/sqlfs.go')
-rw-r--r--dbstore/sqlfs.go38
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
+}