我正在創(chuàng)建一個(gè) crud 應(yīng)用程序,并且正在使用內(nèi)存數(shù)據(jù)庫測試數(shù)據(jù)庫。唯一中斷的測試和函數(shù)是 toggleTask 函數(shù)和測試。功能:func (r *Repository) ToggleTask(task Task) (Task, error) { query := "UPDATE Tasks SET completed = NOT completed WHERE id = (?)" _, err := r.db.Exec(query, task.ID) if err != nil { return task, err } query = "SELECT id, txt, completed FROM Tasks WHERE id = (?) RETURNING *" err = r.db.QueryRow(query, task.ID).Scan(&task.ID, &task.Text, &task.ListID, &task.Completed) if err != nil { return task, err } return task, nil}測試:const ( ToggleTask = "SELECT id, txt, completed FROM Tasks WHERE id = (?) RETURNING *")func TestToggleTask(t *testing.T) { repo := mockDbRepo() list := List{Name: "Test List"} repo.db.Exec(CreateList, list.Name) task := Task{Text: "Test Task", ListID: list.ID} repo.db.Exec(CreateTask, task.Text, task.ListID) completedTask,err := repo.ToggleTask(task) if err != nil { t.Error(err) } if !reflect.DeepEqual(completedTask, task) { t.Errorf("Expected %v, got %v", task, completedTask) }}測試返回給我:SQL 邏輯錯(cuò)誤:“RETURNING”附近:語法錯(cuò)誤 (1)
SQL邏輯錯(cuò)誤: near "RETURNING": syntax error (1) Go
阿波羅的戰(zhàn)車
2022-12-13 16:20:19