it's easy to insert one record and get result like this:
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
}
but how to do batch insert and get all results? i tried several methods but got nothing.
this is one i think should work but it doesn't
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()
The error message is something like this:
quiz-answer_test.go:35: driver: skip fast-path; continue as if unimplemented
thanks in advance