package models // Code generated by xo. DO NOT EDIT. import ( "context" ) // Submissions represents a row from 'submissions'. type Submissions struct { ByUser int `json:"by_user"` // by_user Correct bool `json:"correct"` // correct } // QuestionSubmissions runs a custom query, returning results as Submissions. func QuestionSubmissions(ctx context.Context, db DB, user_id, question_id string, question_part int) (*Submissions, error) { // query const sqlstr = `WITH attempts AS ( ` + `SELECT * FROM question_attempt ` + `WHERE user_id = $1 ` + `AND question_id = $2 ` + `AND question_part = $3 ` + `) ` + `SELECT ` + `c.count AS by_user, ` + `COALESCE(a.correct, FALSE) AS correct ` + `FROM ( ` + `SELECT COUNT(*) as count from attempts ` + `) c ` + `LEFT JOIN attempts a ON a.correct` // run logf(sqlstr, user_id, question_id, question_part) var s Submissions if err := db.QueryRowContext(ctx, sqlstr, user_id, question_id, question_part).Scan(&s.ByUser, &s.Correct); err != nil { return nil, logerror(err) } return &s, nil }