added version to sqlc queryes

This commit is contained in:
Pavel 2024-09-18 19:22:34 +03:00
parent f1687f2e61
commit cd18781525
7 changed files with 31 additions and 17 deletions

@ -286,7 +286,7 @@ WHERE privilege_name = $2
-- name: GetAllAnswersByQuizID :many
SELECT DISTINCT ON (a.question_id)
a.content, a.created_at, a.question_id, a.id, q.questiontype::Text as questiontype, quiz.qid
a.content, a.created_at, a.question_id, a.id,a.version, q.questiontype::Text as questiontype, quiz.qid
FROM
answer a
JOIN
@ -312,12 +312,13 @@ INSERT INTO answer(
browser,
ip,
start,
utm
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)
utm,
version
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)
RETURNING *;
-- name: GetResultAnswers :many
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted, device_type,device,os,browser,ip FROM answer WHERE session = (
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted, device_type,device,os,browser,ip,version FROM answer WHERE session = (
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC;
-- name: GetQuestions :many

@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// sqlc v1.27.0
package sqlcgen

@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// sqlc v1.27.0
package sqlcgen
@ -66,6 +66,7 @@ type Answer struct {
Ip string `db:"ip" json:"ip"`
Start bool `db:"start" json:"start"`
Utm json.RawMessage `db:"utm" json:"utm"`
Version int32 `db:"version" json:"version"`
}
type Field struct {

@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// sqlc v1.27.0
// source: queries.sql
package sqlcgen
@ -1361,7 +1361,7 @@ func (q *Queries) GetAccountWithPrivileges(ctx context.Context, userID string) (
const getAllAnswersByQuizID = `-- name: GetAllAnswersByQuizID :many
SELECT DISTINCT ON (a.question_id)
a.content, a.created_at, a.question_id, a.id, q.questiontype::Text as questiontype, quiz.qid
a.content, a.created_at, a.question_id, a.id,a.version, q.questiontype::Text as questiontype, quiz.qid
FROM
answer a
JOIN
@ -1379,6 +1379,7 @@ type GetAllAnswersByQuizIDRow struct {
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
QuestionID int64 `db:"question_id" json:"question_id"`
ID int64 `db:"id" json:"id"`
Version int32 `db:"version" json:"version"`
Questiontype string `db:"questiontype" json:"questiontype"`
Qid uuid.NullUUID `db:"qid" json:"qid"`
}
@ -1397,6 +1398,7 @@ func (q *Queries) GetAllAnswersByQuizID(ctx context.Context, session sql.NullStr
&i.CreatedAt,
&i.QuestionID,
&i.ID,
&i.Version,
&i.Questiontype,
&i.Qid,
); err != nil {
@ -2413,7 +2415,7 @@ func (q *Queries) GetQuizRule(ctx context.Context, quizid int32) (Rule, error) {
}
const getResultAnswers = `-- name: GetResultAnswers :many
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted, device_type,device,os,browser,ip FROM answer WHERE session = (
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted, device_type,device,os,browser,ip,version FROM answer WHERE session = (
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC
`
@ -2433,6 +2435,7 @@ type GetResultAnswersRow struct {
Os string `db:"os" json:"os"`
Browser string `db:"browser" json:"browser"`
Ip string `db:"ip" json:"ip"`
Version int32 `db:"version" json:"version"`
}
func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAnswersRow, error) {
@ -2460,6 +2463,7 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn
&i.Os,
&i.Browser,
&i.Ip,
&i.Version,
); err != nil {
return nil, err
}
@ -3000,9 +3004,10 @@ INSERT INTO answer(
browser,
ip,
start,
utm
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)
RETURNING id, content, quiz_id, question_id, fingerprint, session, created_at, result, new, deleted, email, device_type, device, os, browser, ip, start, utm
utm,
version
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)
RETURNING id, content, quiz_id, question_id, fingerprint, session, created_at, result, new, deleted, email, device_type, device, os, browser, ip, start, utm, version
`
type InsertAnswersParams struct {
@ -3020,6 +3025,7 @@ type InsertAnswersParams struct {
Ip string `db:"ip" json:"ip"`
Start bool `db:"start" json:"start"`
Utm json.RawMessage `db:"utm" json:"utm"`
Version int32 `db:"version" json:"version"`
}
func (q *Queries) InsertAnswers(ctx context.Context, arg InsertAnswersParams) (Answer, error) {
@ -3038,6 +3044,7 @@ func (q *Queries) InsertAnswers(ctx context.Context, arg InsertAnswersParams) (A
arg.Ip,
arg.Start,
arg.Utm,
arg.Version,
)
var i Answer
err := row.Scan(
@ -3059,6 +3066,7 @@ func (q *Queries) InsertAnswers(ctx context.Context, arg InsertAnswersParams) (A
&i.Ip,
&i.Start,
&i.Utm,
&i.Version,
)
return i, err
}

@ -131,7 +131,7 @@ type Answer struct {
OS string
Start bool
Utm UTMSavingMap
Version int
Version int32
}
type ResultContent struct {
@ -162,6 +162,7 @@ type ResultAnswer struct {
CreatedAt time.Time
QuestionID uint64
AnswerID uint64
Version int32
}
const skey = "squiz"
@ -305,6 +306,7 @@ type AnswerExport struct {
Id uint64 `json:"id"`
New bool `json:"new"`
CreatedAt time.Time `json:"created_at"`
Version int32
}
type UTMSavingMap map[string]string

@ -114,6 +114,7 @@ func (r *AnswerRepository) GetAllAnswersByQuizID(ctx context.Context, session st
CreatedAt: row.CreatedAt.Time,
QuestionID: uint64(row.QuestionID),
AnswerID: uint64(row.ID),
Version: row.Version,
}
results = append(results, resultAnswer)

@ -57,7 +57,7 @@ func (r *ResultRepository) GetQuizResults(ctx context.Context, quizID uint64, re
}
offset := reqExport.Page * reqExport.Limit
mainQuery := "SELECT content, id, new, created_at " + queryBase + " ORDER BY created_at DESC LIMIT $" + strconv.Itoa(len(queryParams)+1) + " OFFSET $" + strconv.Itoa(len(queryParams)+2)
mainQuery := "SELECT content, id, new, created_at,version " + queryBase + " ORDER BY created_at DESC LIMIT $" + strconv.Itoa(len(queryParams)+1) + " OFFSET $" + strconv.Itoa(len(queryParams)+2)
queryParams = append(queryParams, reqExport.Limit, offset)
rows, err := r.pool.QueryContext(ctx, mainQuery, queryParams...)
@ -68,7 +68,7 @@ func (r *ResultRepository) GetQuizResults(ctx context.Context, quizID uint64, re
for rows.Next() {
var answer model.AnswerExport
if err := rows.Scan(&answer.Content, &answer.Id, &answer.New, &answer.CreatedAt); err != nil {
if err := rows.Scan(&answer.Content, &answer.Id, &answer.New, &answer.CreatedAt, &answer.Version); err != nil {
return nil, 0, err
}
@ -118,7 +118,7 @@ func (r *ResultRepository) GetQuizResultsCSV(ctx context.Context, quizID uint64,
var results []model.Answer
mainQuery := `SELECT DISTINCT ON (a.question_id, a.session)
a.id, a.content, a.question_id, a.quiz_id, a.fingerprint, a.session, a.result, a.created_at, a.new, a.deleted
a.id, a.content, a.question_id, a.quiz_id, a.fingerprint, a.session, a.result, a.created_at, a.new, a.deleted,a.version
FROM
answer a
WHERE
@ -151,7 +151,7 @@ func (r *ResultRepository) GetQuizResultsCSV(ctx context.Context, quizID uint64,
for rows.Next() {
var answer model.Answer
if err := rows.Scan(&answer.Id, &answer.Content, &answer.QuestionId, &answer.QuizId, &answer.Fingerprint, &answer.Session, &answer.Result, &answer.CreatedAt, &answer.New, &answer.Deleted); err != nil {
if err := rows.Scan(&answer.Id, &answer.Content, &answer.QuestionId, &answer.QuizId, &answer.Fingerprint, &answer.Session, &answer.Result, &answer.CreatedAt, &answer.New, &answer.Deleted, &answer.Version); err != nil {
return nil, err
}
results = append(results, answer)
@ -245,6 +245,7 @@ func (r *ResultRepository) GetResultAnswers(ctx context.Context, answerID uint64
OS: row.Os,
IP: row.Ip,
Browser: row.Browser,
Version: row.Version,
}
answers = append(answers, answer)