aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/reader
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-07-22 21:01:54 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-07-22 21:01:54 +0100
commitd7d4d0a0476f98d1b0b4c5c454b6d1048a82bdad (patch)
tree11aaba3bab132e3f7d13f73c61d8b14739794f50 /pkg/reader
parentc3d4c6bb51a3d7b89e0fcbb69230db423577ae17 (diff)
more major surgery
Diffstat (limited to '')
-rw-r--r--pkg/datamaps/db.go (renamed from pkg/reader/db.go)16
-rw-r--r--pkg/datamaps/db_test.go (renamed from pkg/reader/db_test.go)6
-rw-r--r--pkg/datamaps/reader.go (renamed from pkg/reader/reader.go)2
-rw-r--r--pkg/datamaps/reader_test.go (renamed from pkg/reader/reader_test.go)2
-rw-r--r--pkg/datamaps/testdata/datamap.csv (renamed from pkg/reader/testdata/datamap.csv)0
-rw-r--r--pkg/datamaps/testdata/test.db (renamed from pkg/reader/testdata/test.db)bin135168 -> 135168 bytes
-rw-r--r--pkg/datamaps/testdata/test_template.xlsx (renamed from pkg/reader/testdata/test_template.xlsx)bin9193 -> 9193 bytes
7 files changed, 10 insertions, 16 deletions
diff --git a/pkg/reader/db.go b/pkg/datamaps/db.go
index 91b6b85..46d07bc 100644
--- a/pkg/reader/db.go
+++ b/pkg/datamaps/db.go
@@ -1,4 +1,4 @@
-package reader
+package datamaps
import (
"database/sql"
@@ -11,12 +11,6 @@ import (
_ "github.com/mattn/go-sqlite3"
)
-type Opts struct {
- DBPath, ImportPath, Name string
- Overwrite, Initial bool
- DMData []DatamapLine
-}
-
func SetupDB(path string) (*sql.DB, error) {
stmt_base := `DROP TABLE IF EXISTS datamap;
CREATE TABLE datamap(id INTEGER PRIMARY KEY, name TEXT, date_created TEXT);
@@ -58,9 +52,9 @@ func SetupDB(path string) (*sql.DB, error) {
// TODO - how do we avoid passing in all these params!??!
//DatamapToDB takes a slice of DatamapLine and writes it to a sqlite3 db file.
-//func DatamapToDB(d_path string, data []DatamapLine, dm_name string, dm_path string) error {
-func DatamapToDB(opts Opts) error {
- fmt.Printf("Importing datamap file %s and naming it %s.\n", opts.ImportPath, opts.Name)
+//func DatafmapToDB(d_path string, data []DatamapLine, dm_name string, dm_path string) error {
+func DatamapToDB(opts Options) error {
+ fmt.Printf("Importing datamap file %s and naming it %s.\n", opts.DMPath, opts.DMName)
// db, err := SetupDB("/home/lemon/.config/datamaps-go/datamaps.db")
// if err != nil {
// return err
@@ -83,7 +77,7 @@ func DatamapToDB(opts Opts) error {
if err != nil {
return err
}
- _, err = stmt_dm.Exec(opts.Name, time.Now())
+ _, err = stmt_dm.Exec(opts.DMName, time.Now())
stmt_dml, err := tx.Prepare("INSERT INTO datamap_line (dm_id, key, sheet, cellref) VALUES(?,?,?,?);")
if err != nil {
diff --git a/pkg/reader/db_test.go b/pkg/datamaps/db_test.go
index 5a96485..e9d5100 100644
--- a/pkg/reader/db_test.go
+++ b/pkg/datamaps/db_test.go
@@ -1,4 +1,4 @@
-package reader
+package datamaps
import (
"testing"
@@ -34,9 +34,9 @@ func TestDatamapGoesIntoDB(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- opts := Opts{
+ opts := Options{
DBPath: "./testdata/test.db",
- Name: "First Datamap",
+ DMName: "First Datamap",
DMData: d,
}
err = DatamapToDB(opts)
diff --git a/pkg/reader/reader.go b/pkg/datamaps/reader.go
index 7479f9f..b67ad3c 100644
--- a/pkg/reader/reader.go
+++ b/pkg/datamaps/reader.go
@@ -1,7 +1,7 @@
/*
reader reads datamap files and populated spreadsheets
*/
-package reader
+package datamaps
import (
"encoding/csv"
diff --git a/pkg/reader/reader_test.go b/pkg/datamaps/reader_test.go
index ca886bc..e89ca79 100644
--- a/pkg/reader/reader_test.go
+++ b/pkg/datamaps/reader_test.go
@@ -1,4 +1,4 @@
-package reader
+package datamaps
import (
"testing"
diff --git a/pkg/reader/testdata/datamap.csv b/pkg/datamaps/testdata/datamap.csv
index d13bd27..d13bd27 100644
--- a/pkg/reader/testdata/datamap.csv
+++ b/pkg/datamaps/testdata/datamap.csv
diff --git a/pkg/reader/testdata/test.db b/pkg/datamaps/testdata/test.db
index d497380..2706a14 100644
--- a/pkg/reader/testdata/test.db
+++ b/pkg/datamaps/testdata/test.db
Binary files differ
diff --git a/pkg/reader/testdata/test_template.xlsx b/pkg/datamaps/testdata/test_template.xlsx
index 77ac56f..77ac56f 100644
--- a/pkg/reader/testdata/test_template.xlsx
+++ b/pkg/datamaps/testdata/test_template.xlsx
Binary files differ