插入一条记录并获得如下结果很容易:
s := "INSERT INTO quiz_answer_details (quiz_answer_id, question_id, type, choices, content) VALUES ($1, $2, $3, $4, $5) RETURNING *"
d, err := fromQuizAnswerDetail(in)
if err != nil {
return nil, err
}
var out quizAnswerDetail
if err := m.core.GetContextOnMaster(ctx, &out, s, d.QuizAnswerID, d.QuestionID, d.Type, d.Choices, d.Content); err != nil {
return nil, err
}
但是如何进行批量插入并获得所有结果?我尝试了几种方法,但一无所获。
这是我认为应该工作的一个,但它没有
s := "INSERT INTO quiz_answer_details (quiz_answer_id, question_id, type, choices, content) VALUES ($1, $2, $3, $4, $5) RETURNING *"
data, err := fromQuizAnswerDetails(ins)
if err != nil {
return nil, err
}
dbs, _ := m.core.GetAllMasters()
stmt, err := dbs[0].PreparexContext(ctx, s)
if err != nil {
return nil, err
}
var out quizAnswerDetails
for _, d := range data {
var detail quizAnswerDetail
if err := stmt.GetContext(ctx, &detail, d.QuizAnswerID, d.QuestionID, d.Type, pq.Array(d.Choices), d.Content); err != nil {
return nil, err
}
out = append(out, detail)
}
return out.to()
错误消息是这样的:
quiz-answer_test.go:35: driver: skip fast-path; continue as if unimplemented
提前致谢