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

View File

@ -31,7 +31,7 @@ func init() {
StartTime: time.Now().UTC(), // XXX get this from MK StartTime: time.Now().UTC(), // XXX get this from MK
}) })
if err != nil { if err != nil {
log.Errorf("%s", err) log.Errorf("DB result error: %s", err)
return err return err
} }

View File

@ -73,14 +73,22 @@ type Result struct {
// Update the Result in the database // Update the Result in the database
func (r Result) Update(db *sqlx.DB) error { 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 return nil
} }
// CreateResult writes the Result to the database a returns a pointer // CreateResult writes the Result to the database a returns a pointer
// to the Result // to the Result
func CreateResult(db *sqlx.DB, r Result) (*Result, error) { 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 res, err := db.NamedExec(`INSERT INTO results
(name, start_time) (name, start_time)
VALUES (:name,:start_time)`, VALUES (:name,:start_time)`,

View File

@ -38,7 +38,7 @@ type Controller struct {
// Init should be called once to initialise the nettest // Init should be called once to initialise the nettest
func (c *Controller) Init(nt *mk.Nettest) { func (c *Controller) Init(nt *mk.Nettest) {
log.Debugf("Init: %s", nt) log.Debugf("Init: %v", nt)
nt.Options = mk.NettestOptions{ nt.Options = mk.NettestOptions{
IncludeIP: c.ctx.Config.Sharing.IncludeIP, IncludeIP: c.ctx.Config.Sharing.IncludeIP,
IncludeASN: c.ctx.Config.Sharing.IncludeASN, IncludeASN: c.ctx.Config.Sharing.IncludeASN,