aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/db/setup_test.go
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-07-19 15:04:41 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-07-19 15:04:41 +0100
commitbd587a070753c3f95ff921c83939bdec3a1284b9 (patch)
tree391ba3c7ec71b648212a7c2e5ada77d79a39b161 /pkg/db/setup_test.go
parent1db96177350b8d785be2728f3d44907c8998d7b0 (diff)
restructure
Diffstat (limited to '')
-rw-r--r--pkg/db/setup_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/db/setup_test.go b/pkg/db/setup_test.go
new file mode 100644
index 0000000..a768432
--- /dev/null
+++ b/pkg/db/setup_test.go
@@ -0,0 +1,68 @@
+package db
+
+import (
+ "testing"
+
+ "github.com/yulqen/datamaps-go/reader"
+)
+
+func TestOpenSQLiteFile(t *testing.T) {
+ db, err := SetupDB("./testdata/test.db")
+ defer db.Close()
+ if err != nil {
+ t.Fatal("Expected to be able to set up the database.")
+ }
+ stmt := `insert into datamap(id, name) values(1,'cock')`
+ _, err = db.Exec(stmt)
+ if err != nil {
+ t.Errorf("Cannot add record to db")
+ }
+ rows, err := db.Query("select name from datamap")
+ if err != nil {
+ t.Errorf("Cannot run select statement")
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var name string
+ err = rows.Scan(&name)
+ if err != nil {
+ t.Errorf("Cannot scan resulting row")
+ }
+ }
+}
+
+// TODO:
+// THIS IS WHAT I WANT TO DO WITH A TRANNY
+// https://github.com/mattn/go-sqlite3/blob/master/_example/simple/simple.go
+// In the production code of course.
+
+// tx, err := db.Begin()
+// if err != nil {
+// log.Fatal(err)
+// }
+// stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)")
+// if err != nil {
+// log.Fatal(err)
+// }
+// defer stmt.Close()
+// for i := 0; i < 100; i++ {
+// _, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i))
+// if err != nil {
+// log.Fatal(err)
+// }
+// }
+// tx.Commit()
+
+func TestDatamapGoesIntoDB(t *testing.T) {
+ 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, _ := reader.ReadDML("testdata/datamap.csv")
+ for _, x := range d {
+ t.Log(x.Key)
+ }
+
+}