implement db update

This commit is contained in:
Will Scott
2018-03-08 02:53:04 -08:00
parent 7151f4270f
commit 7e9a4fc3b7
3 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ func init() {
StartTime: time.Now().UTC(), // XXX get this from MK
})
if err != nil {
log.Errorf("%s", err)
log.Errorf("DB result error: %s", err)
return err
}
+10 -2
View File
@@ -73,14 +73,22 @@ type Result struct {
// Update the Result in the database
func (r Result) Update(db *sqlx.DB) error {
// XXX implement me
log.Debugf("Updating result %v", r)
_, err := db.NamedExec(`UPDATE results SET
(name, start_time, end_time, summary, done, data_usage_up, data_usage_down) =
(:name, :start_time, :end_time, :summary, :done, :data_usage_up, :data_usage_down)
WHERE id = :id`, r)
if err != nil {
return errors.Wrap(err, "updating result")
}
return nil
}
// CreateResult writes the Result to the database a returns a pointer
// to the Result
func CreateResult(db *sqlx.DB, r Result) (*Result, error) {
log.Debugf("Creating result %s", r)
log.Debugf("Creating result %v", r)
res, err := db.NamedExec(`INSERT INTO results
(name, start_time)
VALUES (:name,:start_time)`,