aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/datamaps/reader.go
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-26 17:14:25 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-26 17:14:25 +0100
commit73e42a5e67c5d166a36bfe1473ef1ec05a761168 (patch)
tree773bac8128ed876b2381286be9e64a404b014205 /pkg/datamaps/reader.go
parent4c29ab5529faccf927fb48e1883f8ec1b0464a05 (diff)
adding test and code for pulling []DatamapLine from sqlite3 file
Diffstat (limited to 'pkg/datamaps/reader.go')
-rw-r--r--pkg/datamaps/reader.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/datamaps/reader.go b/pkg/datamaps/reader.go
index bc339e8..ef4ef1a 100644
--- a/pkg/datamaps/reader.go
+++ b/pkg/datamaps/reader.go
@@ -4,6 +4,7 @@
package datamaps
import (
+ "database/sql"
"encoding/csv"
"errors"
"fmt"
@@ -146,6 +147,39 @@ func ReadXLSX(ssheet string) FileData {
return outer
}
+func DMLFromDB(name string, db *sql.DB) []DatamapLine {
+
+ query := `
+ select
+ key, sheet, cellref
+ from datamap_line
+ join datamap on datamap_line.dm_id = datamap.id where datamap.name = ?;
+ `
+ rows, err := db.Query(query, name)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+ var (
+ key string
+ sheet string
+ cellref string
+ )
+ if err := rows.Scan(&key, &sheet, &cellref); err != nil {
+ log.Fatal(err)
+ }
+ log.Printf("key %s\nsheet %s\ncellref %v", key, sheet, cellref)
+ }
+ return make([]DatamapLine, 0)
+}
+
+// func ExtractDBDM(name string, file string) ExtractedData {
+// xdata := ReadXLSX(file)
+// // ddata, err := DMLFromDB(name) // this will need to return a []DatamapLine
+// }
+
//Extract returns the file's data as a map,
// using the datamap as a filter, keyed on sheet name. All values
// are returned as strings.