1405 lines
41 KiB
Go
1405 lines
41 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// versions:
|
||
|
// sqlc v1.25.0
|
||
|
// source: queries.sql
|
||
|
|
||
|
package sqlcgen
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
|
||
|
"github.com/google/uuid"
|
||
|
"github.com/lib/pq"
|
||
|
)
|
||
|
|
||
|
const accountPagination = `-- name: AccountPagination :many
|
||
|
SELECT a.id, a.user_id, a.created_at, a.deleted
|
||
|
FROM account a ORDER BY a.created_at DESC LIMIT $1 OFFSET $2
|
||
|
`
|
||
|
|
||
|
type AccountPaginationParams struct {
|
||
|
Limit int32 `db:"limit" json:"limit"`
|
||
|
Offset int32 `db:"offset" json:"offset"`
|
||
|
}
|
||
|
|
||
|
type AccountPaginationRow struct {
|
||
|
ID uuid.UUID `db:"id" json:"id"`
|
||
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) AccountPagination(ctx context.Context, arg AccountPaginationParams) ([]AccountPaginationRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, accountPagination, arg.Limit, arg.Offset)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []AccountPaginationRow
|
||
|
for rows.Next() {
|
||
|
var i AccountPaginationRow
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.UserID,
|
||
|
&i.CreatedAt,
|
||
|
&i.Deleted,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const archiveQuiz = `-- name: ArchiveQuiz :exec
|
||
|
UPDATE quiz SET archived = true WHERE id=$1 AND accountId=$2
|
||
|
`
|
||
|
|
||
|
type ArchiveQuizParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) ArchiveQuiz(ctx context.Context, arg ArchiveQuizParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, archiveQuiz, arg.ID, arg.Accountid)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const checkAndAddDefault = `-- name: CheckAndAddDefault :exec
|
||
|
UPDATE privileges
|
||
|
SET amount = $1, created_at = NOW()
|
||
|
WHERE privilege_name = $2
|
||
|
AND (amount < $3 OR created_at <= NOW() - INTERVAL '1 month')
|
||
|
`
|
||
|
|
||
|
type CheckAndAddDefaultParams struct {
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount_2 sql.NullInt32 `db:"amount_2" json:"amount_2"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CheckAndAddDefault(ctx context.Context, arg CheckAndAddDefaultParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, checkAndAddDefault, arg.Amount, arg.PrivilegeName, arg.Amount_2)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const checkResultOwner = `-- name: CheckResultOwner :one
|
||
|
SELECT q.accountid FROM answer a JOIN quiz q ON a.quiz_id = q.id WHERE a.id = $1 AND a.deleted = FALSE
|
||
|
`
|
||
|
|
||
|
func (q *Queries) CheckResultOwner(ctx context.Context, id int64) (string, error) {
|
||
|
row := q.db.QueryRowContext(ctx, checkResultOwner, id)
|
||
|
var accountid string
|
||
|
err := row.Scan(&accountid)
|
||
|
return accountid, err
|
||
|
}
|
||
|
|
||
|
const checkResultsOwner = `-- name: CheckResultsOwner :many
|
||
|
SELECT a.id
|
||
|
FROM answer a
|
||
|
JOIN quiz q ON a.quiz_id = q.id
|
||
|
WHERE a.id = ANY($1::bigint[]) AND a.deleted = FALSE AND q.accountid = $2
|
||
|
`
|
||
|
|
||
|
type CheckResultsOwnerParams struct {
|
||
|
Column1 []int64 `db:"column_1" json:"column_1"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CheckResultsOwner(ctx context.Context, arg CheckResultsOwnerParams) ([]int64, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, checkResultsOwner, pq.Array(arg.Column1), arg.Accountid)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []int64
|
||
|
for rows.Next() {
|
||
|
var id int64
|
||
|
if err := rows.Scan(&id); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, id)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const copyQuestion = `-- name: CopyQuestion :one
|
||
|
INSERT INTO question(
|
||
|
quiz_id, title, description, questiontype, required,
|
||
|
page, content, version, parent_ids
|
||
|
)
|
||
|
SELECT $1, title, description, questiontype, required,
|
||
|
page, content, version, parent_ids
|
||
|
FROM question WHERE question.id=$2
|
||
|
RETURNING question.id, quiz_id, created_at, updated_at
|
||
|
`
|
||
|
|
||
|
type CopyQuestionParams struct {
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
}
|
||
|
|
||
|
type CopyQuestionRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CopyQuestion(ctx context.Context, arg CopyQuestionParams) (CopyQuestionRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, copyQuestion, arg.QuizID, arg.ID)
|
||
|
var i CopyQuestionRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.QuizID,
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const copyQuiz = `-- name: CopyQuiz :one
|
||
|
INSERT INTO quiz(
|
||
|
accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
||
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count,answers_count,average_time_passing, super, group_id
|
||
|
)
|
||
|
SELECT accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
||
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count,answers_count,average_time_passing, super, group_id
|
||
|
FROM quiz WHERE quiz.id=$1 AND quiz.accountId=$2
|
||
|
RETURNING id, qid,created_at, updated_at
|
||
|
`
|
||
|
|
||
|
type CopyQuizParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
type CopyQuizRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CopyQuiz(ctx context.Context, arg CopyQuizParams) (CopyQuizRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, copyQuiz, arg.ID, arg.Accountid)
|
||
|
var i CopyQuizRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Qid,
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const copyQuizQuestions = `-- name: CopyQuizQuestions :exec
|
||
|
INSERT INTO question(
|
||
|
quiz_id, title, description, questiontype, required, page, content, version, parent_ids
|
||
|
)
|
||
|
SELECT $2, title, description, questiontype, required, page, content, version, parent_ids
|
||
|
FROM question WHERE question.quiz_id=$1 AND deleted=false
|
||
|
`
|
||
|
|
||
|
type CopyQuizQuestionsParams struct {
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
QuizID_2 int64 `db:"quiz_id_2" json:"quiz_id_2"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CopyQuizQuestions(ctx context.Context, arg CopyQuizQuestionsParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, copyQuizQuestions, arg.QuizID, arg.QuizID_2)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const createAccount = `-- name: CreateAccount :exec
|
||
|
INSERT INTO account (id, user_id, email, created_at, deleted) VALUES ($1, $2, $3, $4, $5)
|
||
|
`
|
||
|
|
||
|
type CreateAccountParams struct {
|
||
|
ID uuid.UUID `db:"id" json:"id"`
|
||
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||
|
Email sql.NullString `db:"email" json:"email"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, createAccount,
|
||
|
arg.ID,
|
||
|
arg.UserID,
|
||
|
arg.Email,
|
||
|
arg.CreatedAt,
|
||
|
arg.Deleted,
|
||
|
)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const deleteAccountById = `-- name: DeleteAccountById :exec
|
||
|
DELETE FROM account WHERE id = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeleteAccountById(ctx context.Context, id uuid.UUID) error {
|
||
|
_, err := q.db.ExecContext(ctx, deleteAccountById, id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const deletePrivilegeByAccID = `-- name: DeletePrivilegeByAccID :exec
|
||
|
DELETE FROM privileges WHERE account_id = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeletePrivilegeByAccID(ctx context.Context, accountID uuid.NullUUID) error {
|
||
|
_, err := q.db.ExecContext(ctx, deletePrivilegeByAccID, accountID)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const deletePrivilegeByID = `-- name: DeletePrivilegeByID :exec
|
||
|
DELETE FROM privileges WHERE id = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeletePrivilegeByID(ctx context.Context, id int32) error {
|
||
|
_, err := q.db.ExecContext(ctx, deletePrivilegeByID, id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const deleteQuestion = `-- name: DeleteQuestion :one
|
||
|
UPDATE question SET deleted=true WHERE id=$1 RETURNING question.id, question.quiz_id, question.title, question.description, question.questiontype, question.required, question.deleted, question.page, question.content, question.version, question.parent_ids, question.created_at, question.updated_at
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error) {
|
||
|
row := q.db.QueryRowContext(ctx, deleteQuestion, id)
|
||
|
var i Question
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.QuizID,
|
||
|
&i.Title,
|
||
|
&i.Description,
|
||
|
&i.Questiontype,
|
||
|
&i.Required,
|
||
|
&i.Deleted,
|
||
|
&i.Page,
|
||
|
&i.Content,
|
||
|
&i.Version,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const deleteQuizByID = `-- name: DeleteQuizByID :one
|
||
|
UPDATE quiz SET deleted=true WHERE quiz.id=$1 AND accountid=$2 RETURNING quiz.id, quiz.qid, quiz.accountid, quiz.deleted, quiz.archived, quiz.fingerprinting, quiz.repeatable, quiz.note_prevented, quiz.mail_notifications, quiz.unique_answers, quiz.super, quiz.group_id, quiz.name, quiz.description, quiz.config, quiz.status, quiz.limit_answers, quiz.due_to, quiz.time_of_passing, quiz.pausable, quiz.version, quiz.version_comment, quiz.parent_ids, quiz.created_at, quiz.updated_at, quiz.questions_count, quiz.answers_count, quiz.average_time_passing, quiz.sessions_count
|
||
|
`
|
||
|
|
||
|
type DeleteQuizByIDParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) DeleteQuizByID(ctx context.Context, arg DeleteQuizByIDParams) (Quiz, error) {
|
||
|
row := q.db.QueryRowContext(ctx, deleteQuizByID, arg.ID, arg.Accountid)
|
||
|
var i Quiz
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Qid,
|
||
|
&i.Accountid,
|
||
|
&i.Deleted,
|
||
|
&i.Archived,
|
||
|
&i.Fingerprinting,
|
||
|
&i.Repeatable,
|
||
|
&i.NotePrevented,
|
||
|
&i.MailNotifications,
|
||
|
&i.UniqueAnswers,
|
||
|
&i.Super,
|
||
|
&i.GroupID,
|
||
|
&i.Name,
|
||
|
&i.Description,
|
||
|
&i.Config,
|
||
|
&i.Status,
|
||
|
&i.LimitAnswers,
|
||
|
&i.DueTo,
|
||
|
&i.TimeOfPassing,
|
||
|
&i.Pausable,
|
||
|
&i.Version,
|
||
|
&i.VersionComment,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
&i.QuestionsCount,
|
||
|
&i.AnswersCount,
|
||
|
&i.AverageTimePassing,
|
||
|
&i.SessionsCount,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const duplicateQuestion = `-- name: DuplicateQuestion :one
|
||
|
INSERT INTO question(
|
||
|
quiz_id, title, description, questiontype, required,
|
||
|
page, content, version, parent_ids
|
||
|
)
|
||
|
SELECT quiz_id, title, description, questiontype, required,
|
||
|
page, content, version, parent_ids
|
||
|
FROM question WHERE question.id=$1
|
||
|
RETURNING question.id, quiz_id, created_at, updated_at
|
||
|
`
|
||
|
|
||
|
type DuplicateQuestionRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) DuplicateQuestion(ctx context.Context, id int64) (DuplicateQuestionRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, duplicateQuestion, id)
|
||
|
var i DuplicateQuestionRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.QuizID,
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getAccAndPrivilegeByEmail = `-- name: GetAccAndPrivilegeByEmail :one
|
||
|
SELECT
|
||
|
a.id,
|
||
|
a.user_id,
|
||
|
a.email,
|
||
|
a.created_at,
|
||
|
p.ID,
|
||
|
p.privilegeid,
|
||
|
p.amount,
|
||
|
p.created_at
|
||
|
FROM
|
||
|
account AS a
|
||
|
LEFT JOIN privileges AS p ON a.id = p.account_id
|
||
|
WHERE
|
||
|
a.user_id = $1
|
||
|
`
|
||
|
|
||
|
type GetAccAndPrivilegeByEmailRow struct {
|
||
|
ID uuid.UUID `db:"id" json:"id"`
|
||
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||
|
Email sql.NullString `db:"email" json:"email"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
ID_2 sql.NullInt32 `db:"id_2" json:"id_2"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt_2 sql.NullTime `db:"created_at_2" json:"created_at_2"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetAccAndPrivilegeByEmail(ctx context.Context, userID sql.NullString) (GetAccAndPrivilegeByEmailRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getAccAndPrivilegeByEmail, userID)
|
||
|
var i GetAccAndPrivilegeByEmailRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.UserID,
|
||
|
&i.Email,
|
||
|
&i.CreatedAt,
|
||
|
&i.ID_2,
|
||
|
&i.Privilegeid,
|
||
|
&i.Amount,
|
||
|
&i.CreatedAt_2,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getAccountWithPrivileges = `-- name: GetAccountWithPrivileges :many
|
||
|
SELECT a.id, a.user_id, a.created_at, a.deleted,
|
||
|
p.id AS privilege_id, p.privilegeID, p.privilege_name, p.amount, p.created_at AS privilege_created_at
|
||
|
FROM account a
|
||
|
LEFT JOIN privileges AS p ON a.id = p.account_id
|
||
|
WHERE a.user_id = $1
|
||
|
`
|
||
|
|
||
|
type GetAccountWithPrivilegesRow struct {
|
||
|
ID uuid.UUID `db:"id" json:"id"`
|
||
|
UserID sql.NullString `db:"user_id" json:"user_id"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||
|
PrivilegeID sql.NullInt32 `db:"privilege_id" json:"privilege_id"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
PrivilegeCreatedAt sql.NullTime `db:"privilege_created_at" json:"privilege_created_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetAccountWithPrivileges(ctx context.Context, userID sql.NullString) ([]GetAccountWithPrivilegesRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getAccountWithPrivileges, userID)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []GetAccountWithPrivilegesRow
|
||
|
for rows.Next() {
|
||
|
var i GetAccountWithPrivilegesRow
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.UserID,
|
||
|
&i.CreatedAt,
|
||
|
&i.Deleted,
|
||
|
&i.PrivilegeID,
|
||
|
&i.Privilegeid,
|
||
|
&i.PrivilegeName,
|
||
|
&i.Amount,
|
||
|
&i.PrivilegeCreatedAt,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getAllAnswersByQuizID = `-- name: GetAllAnswersByQuizID :many
|
||
|
SELECT DISTINCT ON(question_id) content, created_at, question_id, id FROM answer WHERE session = $1 ORDER BY question_id ASC, created_at DESC
|
||
|
`
|
||
|
|
||
|
type GetAllAnswersByQuizIDRow struct {
|
||
|
Content sql.NullString `db:"content" json:"content"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetAllAnswersByQuizID(ctx context.Context, session sql.NullString) ([]GetAllAnswersByQuizIDRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getAllAnswersByQuizID, session)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []GetAllAnswersByQuizIDRow
|
||
|
for rows.Next() {
|
||
|
var i GetAllAnswersByQuizIDRow
|
||
|
if err := rows.Scan(
|
||
|
&i.Content,
|
||
|
&i.CreatedAt,
|
||
|
&i.QuestionID,
|
||
|
&i.ID,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getExpiredPrivilege = `-- name: GetExpiredPrivilege :many
|
||
|
SELECT id, privilegeID, privilege_name, amount, created_at
|
||
|
FROM privileges
|
||
|
WHERE created_at + amount * interval '1 day' < NOW()
|
||
|
AND privilegeid = $1
|
||
|
`
|
||
|
|
||
|
type GetExpiredPrivilegeRow struct {
|
||
|
ID int32 `db:"id" json:"id"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetExpiredPrivilege(ctx context.Context, privilegeid sql.NullString) ([]GetExpiredPrivilegeRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getExpiredPrivilege, privilegeid)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []GetExpiredPrivilegeRow
|
||
|
for rows.Next() {
|
||
|
var i GetExpiredPrivilegeRow
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Privilegeid,
|
||
|
&i.PrivilegeName,
|
||
|
&i.Amount,
|
||
|
&i.CreatedAt,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getPrivilegesByAccountID = `-- name: GetPrivilegesByAccountID :many
|
||
|
SELECT id,privilegeID,privilege_name,amount, created_at FROM privileges WHERE account_id = $1
|
||
|
`
|
||
|
|
||
|
type GetPrivilegesByAccountIDRow struct {
|
||
|
ID int32 `db:"id" json:"id"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetPrivilegesByAccountID(ctx context.Context, accountID uuid.NullUUID) ([]GetPrivilegesByAccountIDRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getPrivilegesByAccountID, accountID)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []GetPrivilegesByAccountIDRow
|
||
|
for rows.Next() {
|
||
|
var i GetPrivilegesByAccountIDRow
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Privilegeid,
|
||
|
&i.PrivilegeName,
|
||
|
&i.Amount,
|
||
|
&i.CreatedAt,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getPrivilegesByAccountIDWC = `-- name: GetPrivilegesByAccountIDWC :many
|
||
|
SELECT p.id,p.privilegeID,p.privilege_name,p.amount, p.created_at FROM privileges as p JOIN account as a on p.account_id = a.id WHERE a.user_id = $1
|
||
|
`
|
||
|
|
||
|
type GetPrivilegesByAccountIDWCRow struct {
|
||
|
ID int32 `db:"id" json:"id"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetPrivilegesByAccountIDWC(ctx context.Context, userID sql.NullString) ([]GetPrivilegesByAccountIDWCRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getPrivilegesByAccountIDWC, userID)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []GetPrivilegesByAccountIDWCRow
|
||
|
for rows.Next() {
|
||
|
var i GetPrivilegesByAccountIDWCRow
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Privilegeid,
|
||
|
&i.PrivilegeName,
|
||
|
&i.Amount,
|
||
|
&i.CreatedAt,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getPrivilegesQuizAccount = `-- name: GetPrivilegesQuizAccount :many
|
||
|
SELECT
|
||
|
p.privilegeID,
|
||
|
p.privilege_name,
|
||
|
p.amount,
|
||
|
p.created_at,
|
||
|
a.id,
|
||
|
a.email,
|
||
|
qz.config
|
||
|
FROM
|
||
|
privileges AS p
|
||
|
INNER JOIN account AS a ON p.account_id = a.id
|
||
|
INNER JOIN quiz AS qz ON qz.accountid = a.user_id
|
||
|
WHERE
|
||
|
qz.id = $1
|
||
|
`
|
||
|
|
||
|
type GetPrivilegesQuizAccountRow struct {
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
ID uuid.UUID `db:"id" json:"id"`
|
||
|
Email sql.NullString `db:"email" json:"email"`
|
||
|
Config sql.NullString `db:"config" json:"config"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetPrivilegesQuizAccount(ctx context.Context, id int64) ([]GetPrivilegesQuizAccountRow, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getPrivilegesQuizAccount, id)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []GetPrivilegesQuizAccountRow
|
||
|
for rows.Next() {
|
||
|
var i GetPrivilegesQuizAccountRow
|
||
|
if err := rows.Scan(
|
||
|
&i.Privilegeid,
|
||
|
&i.PrivilegeName,
|
||
|
&i.Amount,
|
||
|
&i.CreatedAt,
|
||
|
&i.ID,
|
||
|
&i.Email,
|
||
|
&i.Config,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getQuestionHistory = `-- name: GetQuestionHistory :many
|
||
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE question.id = $1 OR question.id = ANY(
|
||
|
SELECT unnest(parent_ids) FROM question WHERE id = $1
|
||
|
) ORDER BY question.id DESC LIMIT $2 OFFSET $3
|
||
|
`
|
||
|
|
||
|
type GetQuestionHistoryParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Limit int32 `db:"limit" json:"limit"`
|
||
|
Offset int32 `db:"offset" json:"offset"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistoryParams) ([]Question, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getQuestionHistory, arg.ID, arg.Limit, arg.Offset)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Question
|
||
|
for rows.Next() {
|
||
|
var i Question
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.QuizID,
|
||
|
&i.Title,
|
||
|
&i.Description,
|
||
|
&i.Questiontype,
|
||
|
&i.Required,
|
||
|
&i.Deleted,
|
||
|
&i.Page,
|
||
|
&i.Content,
|
||
|
&i.Version,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getQuestionTitle = `-- name: GetQuestionTitle :one
|
||
|
SELECT title, questiontype FROM question WHERE id = $1
|
||
|
`
|
||
|
|
||
|
type GetQuestionTitleRow struct {
|
||
|
Title string `db:"title" json:"title"`
|
||
|
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetQuestionTitle(ctx context.Context, id int64) (GetQuestionTitleRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getQuestionTitle, id)
|
||
|
var i GetQuestionTitleRow
|
||
|
err := row.Scan(&i.Title, &i.Questiontype)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getQuestions = `-- name: GetQuestions :many
|
||
|
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at FROM question WHERE quiz_id = $1 AND deleted = FALSE
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]Question, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getQuestions, quizID)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Question
|
||
|
for rows.Next() {
|
||
|
var i Question
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.QuizID,
|
||
|
&i.Title,
|
||
|
&i.Description,
|
||
|
&i.Questiontype,
|
||
|
&i.Required,
|
||
|
&i.Deleted,
|
||
|
&i.Page,
|
||
|
&i.Content,
|
||
|
&i.Version,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getQuizById = `-- name: GetQuizById :one
|
||
|
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE id=$1 AND accountId=$2
|
||
|
`
|
||
|
|
||
|
type GetQuizByIdParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetQuizById(ctx context.Context, arg GetQuizByIdParams) (Quiz, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getQuizById, arg.ID, arg.Accountid)
|
||
|
var i Quiz
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Qid,
|
||
|
&i.Accountid,
|
||
|
&i.Deleted,
|
||
|
&i.Archived,
|
||
|
&i.Fingerprinting,
|
||
|
&i.Repeatable,
|
||
|
&i.NotePrevented,
|
||
|
&i.MailNotifications,
|
||
|
&i.UniqueAnswers,
|
||
|
&i.Super,
|
||
|
&i.GroupID,
|
||
|
&i.Name,
|
||
|
&i.Description,
|
||
|
&i.Config,
|
||
|
&i.Status,
|
||
|
&i.LimitAnswers,
|
||
|
&i.DueTo,
|
||
|
&i.TimeOfPassing,
|
||
|
&i.Pausable,
|
||
|
&i.Version,
|
||
|
&i.VersionComment,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
&i.QuestionsCount,
|
||
|
&i.AnswersCount,
|
||
|
&i.AverageTimePassing,
|
||
|
&i.SessionsCount,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getQuizByQid = `-- name: GetQuizByQid :one
|
||
|
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz
|
||
|
WHERE
|
||
|
deleted = false AND
|
||
|
archived = false AND
|
||
|
status = 'start' AND
|
||
|
qid = $1
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetQuizByQid(ctx context.Context, qid uuid.NullUUID) (Quiz, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getQuizByQid, qid)
|
||
|
var i Quiz
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Qid,
|
||
|
&i.Accountid,
|
||
|
&i.Deleted,
|
||
|
&i.Archived,
|
||
|
&i.Fingerprinting,
|
||
|
&i.Repeatable,
|
||
|
&i.NotePrevented,
|
||
|
&i.MailNotifications,
|
||
|
&i.UniqueAnswers,
|
||
|
&i.Super,
|
||
|
&i.GroupID,
|
||
|
&i.Name,
|
||
|
&i.Description,
|
||
|
&i.Config,
|
||
|
&i.Status,
|
||
|
&i.LimitAnswers,
|
||
|
&i.DueTo,
|
||
|
&i.TimeOfPassing,
|
||
|
&i.Pausable,
|
||
|
&i.Version,
|
||
|
&i.VersionComment,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
&i.QuestionsCount,
|
||
|
&i.AnswersCount,
|
||
|
&i.AverageTimePassing,
|
||
|
&i.SessionsCount,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getQuizConfig = `-- name: GetQuizConfig :one
|
||
|
SELECT config, accountid FROM quiz WHERE id = $1 AND deleted = false
|
||
|
`
|
||
|
|
||
|
type GetQuizConfigRow struct {
|
||
|
Config sql.NullString `db:"config" json:"config"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetQuizConfig(ctx context.Context, id int64) (GetQuizConfigRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getQuizConfig, id)
|
||
|
var i GetQuizConfigRow
|
||
|
err := row.Scan(&i.Config, &i.Accountid)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getQuizHistory = `-- name: GetQuizHistory :many
|
||
|
SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE quiz.id = $1 AND quiz.accountId = $4 OR quiz.id = ANY(
|
||
|
SELECT unnest(parent_ids) FROM quiz WHERE id = $1
|
||
|
) ORDER BY quiz.id DESC LIMIT $2 OFFSET $3
|
||
|
`
|
||
|
|
||
|
type GetQuizHistoryParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Limit int32 `db:"limit" json:"limit"`
|
||
|
Offset int32 `db:"offset" json:"offset"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetQuizHistory(ctx context.Context, arg GetQuizHistoryParams) ([]Quiz, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getQuizHistory,
|
||
|
arg.ID,
|
||
|
arg.Limit,
|
||
|
arg.Offset,
|
||
|
arg.Accountid,
|
||
|
)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Quiz
|
||
|
for rows.Next() {
|
||
|
var i Quiz
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Qid,
|
||
|
&i.Accountid,
|
||
|
&i.Deleted,
|
||
|
&i.Archived,
|
||
|
&i.Fingerprinting,
|
||
|
&i.Repeatable,
|
||
|
&i.NotePrevented,
|
||
|
&i.MailNotifications,
|
||
|
&i.UniqueAnswers,
|
||
|
&i.Super,
|
||
|
&i.GroupID,
|
||
|
&i.Name,
|
||
|
&i.Description,
|
||
|
&i.Config,
|
||
|
&i.Status,
|
||
|
&i.LimitAnswers,
|
||
|
&i.DueTo,
|
||
|
&i.TimeOfPassing,
|
||
|
&i.Pausable,
|
||
|
&i.Version,
|
||
|
&i.VersionComment,
|
||
|
pq.Array(&i.ParentIds),
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
&i.QuestionsCount,
|
||
|
&i.AnswersCount,
|
||
|
&i.AverageTimePassing,
|
||
|
&i.SessionsCount,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const getResultAnswers = `-- name: GetResultAnswers :many
|
||
|
SELECT DISTINCT on (question_id) id, content, quiz_id, question_id, fingerprint, session,created_at, result, new,deleted FROM answer WHERE session = (
|
||
|
SELECT session FROM answer WHERE answer.id = $1) ORDER BY question_id, created_at DESC
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]Answer, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getResultAnswers, id)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Answer
|
||
|
for rows.Next() {
|
||
|
var i Answer
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Content,
|
||
|
&i.QuizID,
|
||
|
&i.QuestionID,
|
||
|
&i.Fingerprint,
|
||
|
&i.Session,
|
||
|
&i.CreatedAt,
|
||
|
&i.Result,
|
||
|
&i.New,
|
||
|
&i.Deleted,
|
||
|
); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
items = append(items, i)
|
||
|
}
|
||
|
if err := rows.Close(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if err := rows.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return items, nil
|
||
|
}
|
||
|
|
||
|
const insertAnswers = `-- name: InsertAnswers :exec
|
||
|
INSERT INTO answer(
|
||
|
content,
|
||
|
quiz_id,
|
||
|
question_id,
|
||
|
fingerprint,
|
||
|
session,
|
||
|
result
|
||
|
) VALUES ($1,$2,$3,$4,$5,$6)
|
||
|
`
|
||
|
|
||
|
type InsertAnswersParams struct {
|
||
|
Content sql.NullString `db:"content" json:"content"`
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
QuestionID int64 `db:"question_id" json:"question_id"`
|
||
|
Fingerprint sql.NullString `db:"fingerprint" json:"fingerprint"`
|
||
|
Session sql.NullString `db:"session" json:"session"`
|
||
|
Result sql.NullBool `db:"result" json:"result"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) InsertAnswers(ctx context.Context, arg InsertAnswersParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, insertAnswers,
|
||
|
arg.Content,
|
||
|
arg.QuizID,
|
||
|
arg.QuestionID,
|
||
|
arg.Fingerprint,
|
||
|
arg.Session,
|
||
|
arg.Result,
|
||
|
)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const insertPrivilege = `-- name: InsertPrivilege :exec
|
||
|
INSERT INTO privileges (privilegeID, account_id, privilege_name, amount, created_at) VALUES ($1, $2, $3, $4, $5)
|
||
|
`
|
||
|
|
||
|
type InsertPrivilegeParams struct {
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
||
|
PrivilegeName sql.NullString `db:"privilege_name" json:"privilege_name"`
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) InsertPrivilege(ctx context.Context, arg InsertPrivilegeParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, insertPrivilege,
|
||
|
arg.Privilegeid,
|
||
|
arg.AccountID,
|
||
|
arg.PrivilegeName,
|
||
|
arg.Amount,
|
||
|
arg.CreatedAt,
|
||
|
)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const insertPrivilegeWC = `-- name: InsertPrivilegeWC :exec
|
||
|
UPDATE privileges SET amount = $1, created_at = $2 WHERE account_id = $3 AND privilegeID = $4
|
||
|
`
|
||
|
|
||
|
type InsertPrivilegeWCParams struct {
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) InsertPrivilegeWC(ctx context.Context, arg InsertPrivilegeWCParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, insertPrivilegeWC,
|
||
|
arg.Amount,
|
||
|
arg.CreatedAt,
|
||
|
arg.AccountID,
|
||
|
arg.Privilegeid,
|
||
|
)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const insertQuestion = `-- name: InsertQuestion :one
|
||
|
INSERT INTO question (
|
||
|
quiz_id,
|
||
|
title,
|
||
|
description,
|
||
|
questiontype,
|
||
|
required,
|
||
|
page,
|
||
|
content,
|
||
|
parent_ids,
|
||
|
updated_at
|
||
|
)
|
||
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
||
|
RETURNING id, created_at, updated_at
|
||
|
`
|
||
|
|
||
|
type InsertQuestionParams struct {
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
Title string `db:"title" json:"title"`
|
||
|
Description sql.NullString `db:"description" json:"description"`
|
||
|
Questiontype interface{} `db:"questiontype" json:"questiontype"`
|
||
|
Required sql.NullBool `db:"required" json:"required"`
|
||
|
Page sql.NullInt16 `db:"page" json:"page"`
|
||
|
Content sql.NullString `db:"content" json:"content"`
|
||
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
type InsertQuestionRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) InsertQuestion(ctx context.Context, arg InsertQuestionParams) (InsertQuestionRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, insertQuestion,
|
||
|
arg.QuizID,
|
||
|
arg.Title,
|
||
|
arg.Description,
|
||
|
arg.Questiontype,
|
||
|
arg.Required,
|
||
|
arg.Page,
|
||
|
arg.Content,
|
||
|
pq.Array(arg.ParentIds),
|
||
|
arg.UpdatedAt,
|
||
|
)
|
||
|
var i InsertQuestionRow
|
||
|
err := row.Scan(&i.ID, &i.CreatedAt, &i.UpdatedAt)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const insertQuiz = `-- name: InsertQuiz :one
|
||
|
INSERT INTO quiz (accountid,
|
||
|
fingerprinting,
|
||
|
repeatable,
|
||
|
note_prevented,
|
||
|
mail_notifications,
|
||
|
unique_answers,
|
||
|
super,
|
||
|
group_id,
|
||
|
name,
|
||
|
description,
|
||
|
config,
|
||
|
status,
|
||
|
limit_answers,
|
||
|
due_to,
|
||
|
time_of_passing,
|
||
|
pausable,
|
||
|
parent_ids,
|
||
|
questions_count,
|
||
|
qid
|
||
|
)
|
||
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19)
|
||
|
RETURNING id, created_at, updated_at, qid
|
||
|
`
|
||
|
|
||
|
type InsertQuizParams struct {
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
Fingerprinting sql.NullBool `db:"fingerprinting" json:"fingerprinting"`
|
||
|
Repeatable sql.NullBool `db:"repeatable" json:"repeatable"`
|
||
|
NotePrevented sql.NullBool `db:"note_prevented" json:"note_prevented"`
|
||
|
MailNotifications sql.NullBool `db:"mail_notifications" json:"mail_notifications"`
|
||
|
UniqueAnswers sql.NullBool `db:"unique_answers" json:"unique_answers"`
|
||
|
Super sql.NullBool `db:"super" json:"super"`
|
||
|
GroupID sql.NullInt64 `db:"group_id" json:"group_id"`
|
||
|
Name sql.NullString `db:"name" json:"name"`
|
||
|
Description sql.NullString `db:"description" json:"description"`
|
||
|
Config sql.NullString `db:"config" json:"config"`
|
||
|
Status interface{} `db:"status" json:"status"`
|
||
|
LimitAnswers sql.NullInt32 `db:"limit_answers" json:"limit_answers"`
|
||
|
DueTo sql.NullInt32 `db:"due_to" json:"due_to"`
|
||
|
TimeOfPassing sql.NullInt32 `db:"time_of_passing" json:"time_of_passing"`
|
||
|
Pausable sql.NullBool `db:"pausable" json:"pausable"`
|
||
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||
|
QuestionsCount sql.NullInt32 `db:"questions_count" json:"questions_count"`
|
||
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||
|
}
|
||
|
|
||
|
type InsertQuizRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) InsertQuiz(ctx context.Context, arg InsertQuizParams) (InsertQuizRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, insertQuiz,
|
||
|
arg.Accountid,
|
||
|
arg.Fingerprinting,
|
||
|
arg.Repeatable,
|
||
|
arg.NotePrevented,
|
||
|
arg.MailNotifications,
|
||
|
arg.UniqueAnswers,
|
||
|
arg.Super,
|
||
|
arg.GroupID,
|
||
|
arg.Name,
|
||
|
arg.Description,
|
||
|
arg.Config,
|
||
|
arg.Status,
|
||
|
arg.LimitAnswers,
|
||
|
arg.DueTo,
|
||
|
arg.TimeOfPassing,
|
||
|
arg.Pausable,
|
||
|
pq.Array(arg.ParentIds),
|
||
|
arg.QuestionsCount,
|
||
|
arg.Qid,
|
||
|
)
|
||
|
var i InsertQuizRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.CreatedAt,
|
||
|
&i.UpdatedAt,
|
||
|
&i.Qid,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const moveToHistory = `-- name: MoveToHistory :one
|
||
|
INSERT INTO question(
|
||
|
quiz_id, title, description, questiontype, required,
|
||
|
page, content, version, parent_ids, deleted
|
||
|
)
|
||
|
SELECT quiz_id, title, description, questiontype, required,
|
||
|
page, content, version, parent_ids, true as deleted
|
||
|
FROM question WHERE question.id=$1
|
||
|
RETURNING question.id, quiz_id, parent_ids
|
||
|
`
|
||
|
|
||
|
type MoveToHistoryRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) MoveToHistory(ctx context.Context, id int64) (MoveToHistoryRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, moveToHistory, id)
|
||
|
var i MoveToHistoryRow
|
||
|
err := row.Scan(&i.ID, &i.QuizID, pq.Array(&i.ParentIds))
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const moveToHistoryQuiz = `-- name: MoveToHistoryQuiz :one
|
||
|
INSERT INTO quiz(deleted,
|
||
|
accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
||
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count,answers_count,average_time_passing, super, group_id
|
||
|
)
|
||
|
SELECT true as deleted, accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
||
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count,answers_count,average_time_passing, super, group_id
|
||
|
FROM quiz WHERE quiz.id=$1 AND quiz.accountid=$2
|
||
|
RETURNING quiz.id, qid, parent_ids
|
||
|
`
|
||
|
|
||
|
type MoveToHistoryQuizParams struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Accountid string `db:"accountid" json:"accountid"`
|
||
|
}
|
||
|
|
||
|
type MoveToHistoryQuizRow struct {
|
||
|
ID int64 `db:"id" json:"id"`
|
||
|
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||
|
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) MoveToHistoryQuiz(ctx context.Context, arg MoveToHistoryQuizParams) (MoveToHistoryQuizRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, moveToHistoryQuiz, arg.ID, arg.Accountid)
|
||
|
var i MoveToHistoryQuizRow
|
||
|
err := row.Scan(&i.ID, &i.Qid, pq.Array(&i.ParentIds))
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const softDeleteResultByID = `-- name: SoftDeleteResultByID :exec
|
||
|
UPDATE answer SET deleted = TRUE WHERE id = $1 AND deleted = FALSE
|
||
|
`
|
||
|
|
||
|
func (q *Queries) SoftDeleteResultByID(ctx context.Context, id int64) error {
|
||
|
_, err := q.db.ExecContext(ctx, softDeleteResultByID, id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const updatePrivilege = `-- name: UpdatePrivilege :exec
|
||
|
UPDATE privileges SET amount = $1, created_at = $2 WHERE account_id = $3 AND privilegeID = $4
|
||
|
`
|
||
|
|
||
|
type UpdatePrivilegeParams struct {
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||
|
AccountID uuid.NullUUID `db:"account_id" json:"account_id"`
|
||
|
Privilegeid sql.NullString `db:"privilegeid" json:"privilegeid"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) UpdatePrivilege(ctx context.Context, arg UpdatePrivilegeParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, updatePrivilege,
|
||
|
arg.Amount,
|
||
|
arg.CreatedAt,
|
||
|
arg.AccountID,
|
||
|
arg.Privilegeid,
|
||
|
)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const updatePrivilegeAmount = `-- name: UpdatePrivilegeAmount :exec
|
||
|
UPDATE privileges SET amount = $1 WHERE id = $2
|
||
|
`
|
||
|
|
||
|
type UpdatePrivilegeAmountParams struct {
|
||
|
Amount sql.NullInt32 `db:"amount" json:"amount"`
|
||
|
ID int32 `db:"id" json:"id"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) UpdatePrivilegeAmount(ctx context.Context, arg UpdatePrivilegeAmountParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, updatePrivilegeAmount, arg.Amount, arg.ID)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const workerStatProcess = `-- name: WorkerStatProcess :exec
|
||
|
WITH answer_aggregates AS (
|
||
|
SELECT
|
||
|
quiz_id,
|
||
|
COUNT(DISTINCT session) AS unique_true_answers_count
|
||
|
FROM
|
||
|
answer
|
||
|
WHERE
|
||
|
result = TRUE
|
||
|
GROUP BY
|
||
|
quiz_id
|
||
|
),
|
||
|
question_aggregates AS (
|
||
|
SELECT
|
||
|
q.id AS quiz_id,
|
||
|
COUNT(qs.id) AS total_questions
|
||
|
FROM
|
||
|
quiz q
|
||
|
INNER JOIN
|
||
|
question qs ON q.id = qs.quiz_id
|
||
|
WHERE
|
||
|
q.deleted = false
|
||
|
AND q.archived = false
|
||
|
AND qs.deleted = false
|
||
|
GROUP BY
|
||
|
q.id
|
||
|
),
|
||
|
session_times_aggregates AS (
|
||
|
SELECT
|
||
|
quiz_id, COUNT(session) as sess,
|
||
|
AVG(extract(epoch FROM session_time)) AS average_session_time
|
||
|
FROM (
|
||
|
SELECT
|
||
|
quiz_id,
|
||
|
session,
|
||
|
(MAX(created_at) - MIN(created_at)) AS session_time
|
||
|
FROM
|
||
|
answer
|
||
|
GROUP BY
|
||
|
quiz_id,
|
||
|
session
|
||
|
) AS all_sessions
|
||
|
GROUP BY
|
||
|
quiz_id
|
||
|
)
|
||
|
UPDATE quiz q
|
||
|
SET
|
||
|
questions_count = COALESCE(qa.total_questions, 0),
|
||
|
answers_count = COALESCE(aa.unique_true_answers_count, 0),
|
||
|
average_time_passing = COALESCE(sta.average_session_time, 0),
|
||
|
sessions_count = COALESCE(sta.sess,0)
|
||
|
FROM
|
||
|
(SELECT id, qid, accountid, deleted, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, super, group_id, name, description, config, status, limit_answers, due_to, time_of_passing, pausable, version, version_comment, parent_ids, created_at, updated_at, questions_count, answers_count, average_time_passing, sessions_count FROM quiz WHERE deleted = FALSE AND archived = FALSE) q_sub
|
||
|
LEFT JOIN answer_aggregates aa ON q_sub.id = aa.quiz_id
|
||
|
LEFT JOIN question_aggregates qa ON q_sub.id = qa.quiz_id
|
||
|
LEFT JOIN session_times_aggregates sta ON q_sub.id = sta.quiz_id
|
||
|
WHERE
|
||
|
q.id = q_sub.id
|
||
|
`
|
||
|
|
||
|
func (q *Queries) WorkerStatProcess(ctx context.Context) error {
|
||
|
_, err := q.db.ExecContext(ctx, workerStatProcess)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const workerTimeoutProcess = `-- name: WorkerTimeoutProcess :exec
|
||
|
UPDATE quiz SET status = 'timeout' WHERE deleted = false AND due_to <> 0 AND due_to < EXTRACT(epoch FROM CURRENT_TIMESTAMP)
|
||
|
`
|
||
|
|
||
|
func (q *Queries) WorkerTimeoutProcess(ctx context.Context) error {
|
||
|
_, err := q.db.ExecContext(ctx, workerTimeoutProcess)
|
||
|
return err
|
||
|
}
|