aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/datamaps
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-26 15:21:22 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-26 15:21:22 +0100
commit9a7852a83aaecb8f203fdba6805a9b1b264ae923 (patch)
treef4d53dbd9155c45e364dabf7af3c98293c68af97 /pkg/datamaps
parent20d81808c238c5556c42b846cafcb2403e691ccf (diff)
spacing
Diffstat (limited to 'pkg/datamaps')
-rw-r--r--pkg/datamaps/db.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go
index ee934c4..9f9d669 100644
--- a/pkg/datamaps/db.go
+++ b/pkg/datamaps/db.go
@@ -66,24 +66,29 @@ func DatamapToDB(opts *Options) error {
if err != nil {
return errors.New("Cannot open that damn database file")
}
+
tx, err := d.Begin()
if err != nil {
return err
}
+
pragma := "PRAGMA foreign_keys = ON;"
_, err = d.Exec(pragma)
if err != nil {
log.Printf("%q: %s\n", err, pragma)
return err
}
+
stmtDm, err := tx.Prepare("INSERT INTO datamap (name, date_created) VALUES(?,?)")
if err != nil {
return err
}
+
res, err := stmtDm.Exec(opts.DMName, time.Now())
if err != nil {
return err
}
+
lastId, err := res.LastInsertId()
if err != nil {
return err
@@ -93,8 +98,10 @@ func DatamapToDB(opts *Options) error {
if err != nil {
return err
}
+
defer stmtDm.Close()
defer stmtDml.Close()
+
for _, dml := range data {
_, err = stmtDml.Exec(lastId, dml.Key, dml.Sheet, dml.Cellref)
if err != nil {
@@ -105,5 +112,6 @@ func DatamapToDB(opts *Options) error {
if err != nil {
return err
}
+
return nil
}