diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-07-28 21:43:00 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-07-28 21:43:00 +0100 |
commit | c9d9d3b6a67a5ed88cbb0eb63799725188d98b35 (patch) | |
tree | 8b0897a1058b24fea201781ce982172917349196 | |
parent | 07b695ccaf2c4485c6278f0d543b0bb223abb58c (diff) |
tidying
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | pkg/datamaps/config.go | 4 | ||||
-rw-r--r-- | pkg/datamaps/db.go | 15 |
3 files changed, 16 insertions, 10 deletions
@@ -21,3 +21,10 @@ return_data.ret_id=return.id;` `select datamap.name, datamap_line.key, datamap_line.sheet, return.name, return_data.filename, return_data.value from datamap, datamap_line, return, return_data where datamap_line.dm_id=datamap.id;` + +### Simple output to spreadsheet from sqlite3: +`.excel` +`select return.name, datamap_line.key, return_data.filename, +datamap_line.sheet, datamap_line.cellref, return_data.value from datamap_line, +return, return_data where (return_data.dml_id=datamap_line.id AND +datamap_line.key like '%MM6%');` diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go index 191dd6f..d7d2820 100644 --- a/pkg/datamaps/config.go +++ b/pkg/datamaps/config.go @@ -63,7 +63,7 @@ func SetUp() (string, error) { dbPath := filepath.Join(configPath, dbName) if _, err := os.Stat(configPath); os.IsNotExist(err) { log.Println("Config directory does not exist.") - log.Printf("Creating config directory %s\n", configPath) + log.Printf("Creating config directory %s.\n", configPath) if err := os.Mkdir(filepath.Join(dir, "datamaps"), 0700); err != nil { return "", err } @@ -76,7 +76,7 @@ func SetUp() (string, error) { if err != nil { return "", err } - log.Printf("Creating database file at %s\n", dbPath) + log.Printf("Creating database file at %s.\n", dbPath) _, err := setupDB(dbPath) if err != nil { return "", err diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go index 152ebc4..c71bc12 100644 --- a/pkg/datamaps/db.go +++ b/pkg/datamaps/db.go @@ -84,7 +84,7 @@ func setupDB(path string) (*sql.DB, error) { // Import a directory of xlsx files to the database, using the datamap // to filter the data. func ImportToDB(opts *Options) error { - fmt.Printf("Import files in %s\n\tas return named %s\n\tusing datamap named %s\n", opts.XLSXPath, opts.ReturnName, opts.DMName) + log.Printf("Importing files in %s as return named %s using datamap named %s.", opts.XLSXPath, opts.ReturnName, opts.DMName) target, err := getTargetFiles(opts.XLSXPath) if err != nil { @@ -108,7 +108,7 @@ func ImportToDB(opts *Options) error { // DatamapToDB takes a slice of datamapLine and writes it to a sqlite3 db file. func DatamapToDB(opts *Options) error { - fmt.Printf("Importing datamap file %s and naming it %s.\n", opts.DMPath, opts.DMName) + log.Printf("Importing datamap file %s and naming it %s.\n", opts.DMPath, opts.DMName) data, err := ReadDML(opts.DMPath) if err != nil { @@ -176,7 +176,7 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB) if err != nil { return err } - fmt.Printf("Extracting from %s\n", file) + log.Printf("Extracting from %s.\n", file) // If there is already a return with a matching name, use that. rtnQuery, err := db.Prepare("select id from return where (return.name=?)") @@ -188,7 +188,7 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB) var retId int64 err = rtnQuery.QueryRow(return_name).Scan(&retId) if err != nil { - fmt.Printf("Couldn't find an existing return named %s\n", return_name) + log.Printf("Couldn't find an existing return named '%s' so let's create it.\n", return_name) } if retId == 0 { @@ -201,7 +201,7 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB) res, err := stmtReturn.Exec(return_name, time.Now()) if err != nil { err := fmt.Errorf("%v\nCannot create %s", err, return_name) - fmt.Println(err.Error()) + log.Println(err.Error()) os.Exit(1) } @@ -220,7 +220,6 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB) for sheetName, sheetData := range d { for cellRef, cellData := range sheetData { - // fmt.Printf("Getting %s from sheet %s\n", cellRef, sheetName) dmlQuery, err := db.Prepare("select id from datamap_line where (sheet=? and cellref=?)") if err != nil { @@ -232,8 +231,8 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB) var dmlId *int if err := dmlIdRow.Scan(&dmlId); err != nil { - err := fmt.Errorf("cannot find a datamap_line row for %s and %s: %s\n", sheetName, cellRef, err) - fmt.Println(err.Error()) + err := fmt.Errorf("cannot find a datamap_line row for %s and %s: %s.\n", sheetName, cellRef, err) + log.Println(err.Error()) } insertStmt, err := db.Prepare("insert into return_data (dml_id, ret_id, filename, value) values(?,?,?,?)") |