From ba18d011bd888a155f14116a6221a81d574bf94f Mon Sep 17 00:00:00 2001 From: Deepak Date: Tue, 29 Dec 2020 16:16:09 -0600 Subject: [PATCH] Fixes Postgres to be postgres style bindvars --- models/models_test.go | 1 - store/postgres.go | 2 +- store/postgres_test.go | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/models/models_test.go b/models/models_test.go index 27ab7a6..b45a4b4 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -6,7 +6,6 @@ import ( "testing" ) - type multiStore struct { actions []*models.Action plans []*models.Plan diff --git a/store/postgres.go b/store/postgres.go index 30a96f9..e05fe62 100644 --- a/store/postgres.go +++ b/store/postgres.go @@ -29,7 +29,7 @@ func (store *postgresStore) SelectActions() ([]*models.Action, error) { func (store *postgresStore) SelectActionByID(id int) (*models.Action, error) { action := models.Action{} - err := store.db.Get(&action, "SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = ?", id) + err := store.db.Get(&action, store.db.Rebind("SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = ?"), id) if err != nil { return nil, err } diff --git a/store/postgres_test.go b/store/postgres_test.go index 0a099e4..cc461de 100644 --- a/store/postgres_test.go +++ b/store/postgres_test.go @@ -120,7 +120,7 @@ func TestSelectActionById(t *testing.T) { "plan_id"}). AddRow(idToUse, desc, estChunks, compChunks, completeTime, createTime, updateTime, idToUse) - mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = \\?"). + mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = \\$1"). WithArgs(1). WillReturnRows(rows) @@ -181,7 +181,7 @@ func TestErrActionByID(t *testing.T) { assert := assert.New(t) str, mock := getDbMock(t) - mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = \\?").WillReturnError(fmt.Errorf("example error")) + mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = \\$1").WillReturnError(fmt.Errorf("example error")) // function under test action, err := str.SelectActionByID(1) // test results