diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-20 20:52:42 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-20 20:52:42 +0100 |
commit | 341f0bd5dfd640a0adf7cceb61fabeab7e2cebb1 (patch) | |
tree | e7c2bbe4d166ce34fcf556cf146748a4b97fd4a9 | |
parent | c7766d087d6cdd691e60f4b2d317030543209c08 (diff) |
wired up to main but setup not yet right - need proper config setup
-rw-r--r-- | cmd/main.go | 7 | ||||
-rw-r--r-- | pkg/db/setup.go | 7 | ||||
-rw-r--r-- | pkg/db/setup_test.go | 13 | ||||
-rw-r--r-- | pkg/db/testdata/test.db | bin | 135168 -> 135168 bytes |
4 files changed, 20 insertions, 7 deletions
diff --git a/cmd/main.go b/cmd/main.go index 5e77583..508d9a1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" + "github.com/yulqen/datamaps-go/pkg/db" "github.com/yulqen/datamaps-go/pkg/reader" ) @@ -79,11 +80,15 @@ func main() { fmt.Println(" name:", *nameFlg) fmt.Println(" overwrite:", *overwriteFlg) fmt.Println(" initial:", *initialFlg) + data, err := reader.ReadDML(*importFlg) if err != nil { log.Fatal(err) } - fmt.Println(data[3].Key) + err = db.DatamapToDB(data, *nameFlg, *importFlg) + if err != nil { + log.Fatal(err) + } case "setup": setupCmd.Parse(os.Args[2:]) _, err := setUp() diff --git a/pkg/db/setup.go b/pkg/db/setup.go index ef53cf6..d0c0064 100644 --- a/pkg/db/setup.go +++ b/pkg/db/setup.go @@ -49,7 +49,12 @@ func SetupDB(path string) (*sql.DB, error) { } //DatamapToDB takes a slice of DatamapLine and writes it to a sqlite3 db file. -func DatamapToDB(data []reader.DatamapLine, db *sql.DB, dm_name string) error { +func DatamapToDB(data []reader.DatamapLine, dm_name string, dm_path string) error { + log.Printf("Importing Datamap") + db, err := SetupDB("/home/lemon/.config/datamaps-go/datamaps.db") + if err != nil { + return err + } tx, err := db.Begin() if err != nil { return err diff --git a/pkg/db/setup_test.go b/pkg/db/setup_test.go index 3787d2e..a8868ed 100644 --- a/pkg/db/setup_test.go +++ b/pkg/db/setup_test.go @@ -54,13 +54,16 @@ func TestOpenSQLiteFile(t *testing.T) { // tx.Commit() func TestDatamapGoesIntoDB(t *testing.T) { - db, err := SetupDB("./testdata/test.db") // we set up, then just open it. - defer db.Close() + // db, err := SetupDB("./testdata/test.db") // we set up, then just open it. + // defer db.Close() + // if err != nil { + // t.Fatal("Expected to be able to set up the database.") + // } + d, err := reader.ReadDML("./testdata/datamap.csv") if err != nil { - t.Fatal("Expected to be able to set up the database.") + t.Fatal(err) } - d, _ := reader.ReadDML("./testdata/datamap.csv") - err = DatamapToDB(d, db, "First Datamap") + err = DatamapToDB(d, "First Datamap", "./testdata/test.db") if err != nil { t.Errorf("Unable to write datamap to database file because %v.", err) } diff --git a/pkg/db/testdata/test.db b/pkg/db/testdata/test.db Binary files differindex 81de353..a85f6ec 100644 --- a/pkg/db/testdata/test.db +++ b/pkg/db/testdata/test.db |