From 6432f9a7465453bc2efa11b736e19d58a0503e43 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 27 Jul 2020 16:16:45 +0100 Subject: partially through writing code for commiting extracted data to the database --- pkg/datamaps/db.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go index 76564dc..f1204a9 100644 --- a/pkg/datamaps/db.go +++ b/pkg/datamaps/db.go @@ -167,6 +167,35 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB) return err } fmt.Printf("Extracting from %s\n", file) - fmt.Printf("Data is: %#v\n", d["Introduction"]["C17"].Value) + // fmt.Printf("Data is: %#v\n", d["Introduction"]["C17"].Value) + + stmtReturn, err := db.Prepare("insert into return(name, date_created) values(?,?)") + if err != nil { + log.Fatal(err) + } + + defer stmtReturn.Close() + + res, err := stmtReturn.Exec(return_name, time.Now()) + if err != nil { + log.Fatal(err) + } + + rId, err := res.LastInsertId() + if err != nil { + log.Fatal(err) + } + + // We're going to need a transaction for the big stuff + tx, err := db.Begin() + if err != nil { + return err + } + + stmtValues, err := tx.Prepare("INSERT INTO return_data (name, date_created) VALUES(?,?)") + if err != nil { + return err + } + return nil } -- cgit v1.2.3