diff options
Diffstat (limited to '')
-rw-r--r-- | cmd/main.go | 21 | ||||
-rw-r--r-- | pkg/db/setup.go | 9 | ||||
-rw-r--r-- | pkg/db/testdata/test.db | bin | 135168 -> 12288 bytes |
3 files changed, 25 insertions, 5 deletions
diff --git a/cmd/main.go b/cmd/main.go index 508d9a1..1f6e4ab 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,14 +14,19 @@ import ( "github.com/yulqen/datamaps-go/pkg/reader" ) +const ( + config_dir_name = "datamaps-go" + db_name = "datamaps.db" +) + func setUp() (string, error) { dir, err := os.UserConfigDir() if err != nil { return "", err } // check if config folder exists - config_path := filepath.Join(dir, "datamaps-go") - db_path := filepath.Join(config_path, "datamaps.db") + config_path := filepath.Join(dir, config_dir_name) + db_path := filepath.Join(config_path, db_name) if _, err := os.Stat(config_path); os.IsNotExist(err) { log.Println("Config directory does not exist.") log.Printf("Creating config directory %s\n", config_path) @@ -81,10 +86,22 @@ func main() { fmt.Println(" overwrite:", *overwriteFlg) fmt.Println(" initial:", *initialFlg) + dir, err := os.UserConfigDir() + if err != nil { + os.Exit(1) + } + // check if config folder exists + config_path := filepath.Join(dir, config_dir_name) + + if _, err := os.Stat(config_path); os.IsNotExist(err) { + fmt.Println("Config directory and database does not exist. Run datamaps setup to fix.") + os.Exit(1) + } data, err := reader.ReadDML(*importFlg) if err != nil { log.Fatal(err) } + err = db.DatamapToDB(data, *nameFlg, *importFlg) if err != nil { log.Fatal(err) diff --git a/pkg/db/setup.go b/pkg/db/setup.go index d0c0064..e5179ed 100644 --- a/pkg/db/setup.go +++ b/pkg/db/setup.go @@ -3,6 +3,7 @@ package db import ( "database/sql" "errors" + "fmt" "log" "os" "time" @@ -37,12 +38,14 @@ func SetupDB(path string) (*sql.DB, error) { pragma := "PRAGMA foreign_keys = ON;" _, err = db.Exec(pragma) if err != nil { - log.Printf("%q: %s\n", err, pragma) + // log.Printf("%q: %s\n", err, pragma) + return nil, err } _, err = db.Exec(stmt_base) if err != nil { - log.Printf("%q: %s\n", err, stmt_base) + // log.Printf("%q: %s\n", err, stmt_base) + return nil, err } return db, nil @@ -50,7 +53,7 @@ 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, dm_name string, dm_path string) error { - log.Printf("Importing Datamap") + fmt.Printf("Importing datamap file %s and naming it %s.\n", dm_path, dm_name) db, err := SetupDB("/home/lemon/.config/datamaps-go/datamaps.db") if err != nil { return err diff --git a/pkg/db/testdata/test.db b/pkg/db/testdata/test.db Binary files differindex a85f6ec..bb59dde 100644 --- a/pkg/db/testdata/test.db +++ b/pkg/db/testdata/test.db |