Adds insert plan function
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.deepak.science/deepak/gogmagog/models"
|
||||
"gitea.deepak.science/deepak/gogmagog/util"
|
||||
"github.com/jmoiron/sqlx"
|
||||
@@ -55,5 +54,17 @@ func (store *postgresStore) SelectPlanByID(id int) (*models.Plan, error) {
|
||||
}
|
||||
|
||||
func (store *postgresStore) InsertPlan(plan *models.Plan) (int, error) {
|
||||
return 0, fmt.Errorf("Unimplemented method")
|
||||
queryString := store.db.Rebind("INSERT INTO plans (plan_date) VALUES (?) RETURNING plan_id")
|
||||
tx := store.db.MustBegin()
|
||||
var id int
|
||||
err := tx.Get(&id, queryString, plan.PlanDate)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return -1, err
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user