reworked schema and new sqlc generate
This commit is contained in:
parent
42ba11f5a0
commit
8fea5d95c3
@ -700,7 +700,7 @@ SELECT *, COUNT(*) OVER() as total_count FROM fields WHERE Deleted = false ORDE
|
||||
WITH user_data AS (
|
||||
SELECT AmoID
|
||||
FROM users
|
||||
WHERE AccountID = $1
|
||||
WHERE users.AccountID = $1
|
||||
)
|
||||
INSERT INTO tags (amoID, accountID, Entity, name, color, createdAt)
|
||||
SELECT (new_tags->>'Amoid')::INT,
|
||||
|
@ -49,7 +49,7 @@ type Field struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Entity interface{} `db:"entity" json:"entity"`
|
||||
Type string `db:"type" json:"type"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
@ -58,8 +58,8 @@ type Pipeline struct {
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Isarchive sql.NullBool `db:"isarchive" json:"isarchive"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Isarchive bool `db:"isarchive" json:"isarchive"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
@ -73,53 +73,53 @@ type Privilege struct {
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
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"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Page sql.NullInt16 `db:"page" json:"page"`
|
||||
Content sql.NullString `db:"content" json:"content"`
|
||||
Version sql.NullInt16 `db:"version" json:"version"`
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
Utm json.RawMessage `db:"utm" json:"utm"`
|
||||
Rules json.RawMessage `db:"rules" json:"rules"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
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"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Page sql.NullInt16 `db:"page" json:"page"`
|
||||
Content sql.NullString `db:"content" json:"content"`
|
||||
Version sql.NullInt16 `db:"version" json:"version"`
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
type Quiz struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Archived sql.NullBool `db:"archived" json:"archived"`
|
||||
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"`
|
||||
Version sql.NullInt16 `db:"version" json:"version"`
|
||||
VersionComment sql.NullString `db:"version_comment" json:"version_comment"`
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
QuestionsCount sql.NullInt32 `db:"questions_count" json:"questions_count"`
|
||||
AnswersCount sql.NullInt32 `db:"answers_count" json:"answers_count"`
|
||||
AverageTimePassing sql.NullInt32 `db:"average_time_passing" json:"average_time_passing"`
|
||||
SessionsCount sql.NullInt32 `db:"sessions_count" json:"sessions_count"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Qid uuid.NullUUID `db:"qid" json:"qid"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Archived sql.NullBool `db:"archived" json:"archived"`
|
||||
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"`
|
||||
Version sql.NullInt16 `db:"version" json:"version"`
|
||||
VersionComment sql.NullString `db:"version_comment" json:"version_comment"`
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
QuestionsCount sql.NullInt32 `db:"questions_count" json:"questions_count"`
|
||||
AnswersCount sql.NullInt32 `db:"answers_count" json:"answers_count"`
|
||||
AverageTimePassing sql.NullInt32 `db:"average_time_passing" json:"average_time_passing"`
|
||||
SessionsCount sql.NullInt32 `db:"sessions_count" json:"sessions_count"`
|
||||
Utm json.RawMessage `db:"utm" json:"utm"`
|
||||
Rules json.RawMessage `db:"rules" json:"rules"`
|
||||
}
|
||||
|
||||
type Step struct {
|
||||
@ -129,7 +129,7 @@ type Step struct {
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ type Tag struct {
|
||||
Entity interface{} `db:"entity" json:"entity"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ type User struct {
|
||||
Email string `db:"email" json:"email"`
|
||||
Role string `db:"role" json:"role"`
|
||||
Group pqtype.NullRawMessage `db:"Group" json:"Group"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||
|
@ -8,6 +8,7 @@ package sqlcgen
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@ -133,7 +134,7 @@ func (q *Queries) CheckAndAddDefault(ctx context.Context, arg CheckAndAddDefault
|
||||
}
|
||||
|
||||
const checkExpired = `-- name: CheckExpired :many
|
||||
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens WHERE Expiration <= EXTRACT(EPOCH FROM NOW()) + (10 * 60)
|
||||
SELECT accountid, refreshtoken, accesstoken, authcode, expiration, createdat FROM tokens WHERE Expiration <= TO_TIMESTAMP(EXTRACT(EPOCH FROM NOW()) + (10 * 60))
|
||||
`
|
||||
|
||||
func (q *Queries) CheckExpired(ctx context.Context) ([]Token, error) {
|
||||
@ -212,6 +213,65 @@ func (q *Queries) CheckResultsOwner(ctx context.Context, arg CheckResultsOwnerPa
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const checkTags = `-- name: CheckTags :many
|
||||
WITH user_data AS (
|
||||
SELECT AmoID
|
||||
FROM users
|
||||
WHERE users.AccountID = $1
|
||||
)
|
||||
INSERT INTO tags (amoID, accountID, Entity, name, color, createdAt)
|
||||
SELECT (new_tags->>'Amoid')::INT,
|
||||
user_data.AmoID,
|
||||
CAST(new_tags->>'Entity' AS entitytype),
|
||||
new_tags->>'Name',
|
||||
new_tags->>'Color',
|
||||
CURRENT_TIMESTAMP
|
||||
FROM json_array_elements($2::json[]) AS new_tags
|
||||
JOIN user_data ON true
|
||||
ON CONFLICT (amoID, accountID, entity) DO UPDATE
|
||||
SET name = EXCLUDED.name,
|
||||
color = EXCLUDED.color,
|
||||
createdAt = CURRENT_TIMESTAMP
|
||||
RETURNING id, amoid, accountid, entity, name, color, deleted, createdat
|
||||
`
|
||||
|
||||
type CheckTagsParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Column2 []json.RawMessage `db:"column_2" json:"column_2"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckTags(ctx context.Context, arg CheckTagsParams) ([]Tag, error) {
|
||||
rows, err := q.db.QueryContext(ctx, checkTags, arg.Accountid, pq.Array(arg.Column2))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Tag
|
||||
for rows.Next() {
|
||||
var i Tag
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Accountid,
|
||||
&i.Entity,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.Deleted,
|
||||
&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 checkUsers = `-- name: CheckUsers :exec
|
||||
UPDATE users SET Name = $1, "Group" = $2, Email = $3, Role = $4 WHERE AmoID = $5
|
||||
`
|
||||
@ -383,7 +443,7 @@ type CreateAmoAccountParams struct {
|
||||
Email string `db:"email" json:"email"`
|
||||
Role string `db:"role" json:"role"`
|
||||
Group pqtype.NullRawMessage `db:"Group" json:"Group"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||
@ -462,7 +522,7 @@ func (q *Queries) DeletePrivilegeByID(ctx context.Context, id int32) error {
|
||||
}
|
||||
|
||||
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, question.utm, question.rules
|
||||
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) {
|
||||
@ -482,14 +542,12 @@ func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error
|
||||
pq.Array(&i.ParentIds),
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Utm,
|
||||
&i.Rules,
|
||||
)
|
||||
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
|
||||
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, quiz.utm, quiz.rules
|
||||
`
|
||||
|
||||
type DeleteQuizByIDParams struct {
|
||||
@ -530,6 +588,8 @@ func (q *Queries) DeleteQuizByID(ctx context.Context, arg DeleteQuizByIDParams)
|
||||
&i.AnswersCount,
|
||||
&i.AverageTimePassing,
|
||||
&i.SessionsCount,
|
||||
&i.Utm,
|
||||
&i.Rules,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -1083,6 +1143,114 @@ func (q *Queries) GetExpiredPrivilege(ctx context.Context, privilegeid sql.NullS
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getFieldsWithPagination = `-- name: GetFieldsWithPagination :many
|
||||
SELECT id, amoid, code, accountid, name, entity, type, deleted, createdat, COUNT(*) OVER() as total_count FROM fields WHERE Deleted = false ORDER BY ID OFFSET ($1 - 1) * $2 LIMIT $2
|
||||
`
|
||||
|
||||
type GetFieldsWithPaginationParams struct {
|
||||
Column1 interface{} `db:"column_1" json:"column_1"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
}
|
||||
|
||||
type GetFieldsWithPaginationRow struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
Code string `db:"code" json:"code"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Entity interface{} `db:"entity" json:"entity"`
|
||||
Type string `db:"type" json:"type"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetFieldsWithPagination(ctx context.Context, arg GetFieldsWithPaginationParams) ([]GetFieldsWithPaginationRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getFieldsWithPagination, arg.Column1, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetFieldsWithPaginationRow
|
||||
for rows.Next() {
|
||||
var i GetFieldsWithPaginationRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Code,
|
||||
&i.Accountid,
|
||||
&i.Name,
|
||||
&i.Entity,
|
||||
&i.Type,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); 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 getPipelinesWithPagination = `-- name: GetPipelinesWithPagination :many
|
||||
SELECT id, amoid, accountid, name, isarchive, deleted, createdat, COUNT(*) OVER() as total_count FROM pipelines WHERE Deleted = false ORDER BY ID OFFSET ($1 - 1) * $2 LIMIT $2
|
||||
`
|
||||
|
||||
type GetPipelinesWithPaginationParams struct {
|
||||
Column1 interface{} `db:"column_1" json:"column_1"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
}
|
||||
|
||||
type GetPipelinesWithPaginationRow struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Isarchive bool `db:"isarchive" json:"isarchive"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetPipelinesWithPagination(ctx context.Context, arg GetPipelinesWithPaginationParams) ([]GetPipelinesWithPaginationRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getPipelinesWithPagination, arg.Column1, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetPipelinesWithPaginationRow
|
||||
for rows.Next() {
|
||||
var i GetPipelinesWithPaginationRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Accountid,
|
||||
&i.Name,
|
||||
&i.Isarchive,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); 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
|
||||
`
|
||||
@ -1235,7 +1403,7 @@ func (q *Queries) GetQidOwner(ctx context.Context, qid uuid.NullUUID) (string, e
|
||||
}
|
||||
|
||||
const getQuestionHistory = `-- name: GetQuestionHistory :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, utm, rules FROM question WHERE question.id = $1 OR question.id = ANY(
|
||||
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
|
||||
`
|
||||
@ -1269,8 +1437,6 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
||||
pq.Array(&i.ParentIds),
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Utm,
|
||||
&i.Rules,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1306,31 +1472,15 @@ 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 ORDER BY page ASC
|
||||
`
|
||||
|
||||
type GetQuestionsRow struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
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"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Page sql.NullInt16 `db:"page" json:"page"`
|
||||
Content sql.NullString `db:"content" json:"content"`
|
||||
Version sql.NullInt16 `db:"version" json:"version"`
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestionsRow, error) {
|
||||
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 []GetQuestionsRow
|
||||
var items []Question
|
||||
for rows.Next() {
|
||||
var i GetQuestionsRow
|
||||
var i Question
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.QuizID,
|
||||
@ -1360,7 +1510,7 @@ func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestion
|
||||
}
|
||||
|
||||
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
|
||||
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, utm, rules FROM quiz WHERE id=$1 AND accountId=$2
|
||||
`
|
||||
|
||||
type GetQuizByIdParams struct {
|
||||
@ -1401,12 +1551,14 @@ func (q *Queries) GetQuizById(ctx context.Context, arg GetQuizByIdParams) (Quiz,
|
||||
&i.AnswersCount,
|
||||
&i.AverageTimePassing,
|
||||
&i.SessionsCount,
|
||||
&i.Utm,
|
||||
&i.Rules,
|
||||
)
|
||||
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
|
||||
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, utm, rules FROM quiz
|
||||
WHERE
|
||||
deleted = false AND
|
||||
archived = false AND
|
||||
@ -1447,6 +1599,8 @@ func (q *Queries) GetQuizByQid(ctx context.Context, qid uuid.NullUUID) (Quiz, er
|
||||
&i.AnswersCount,
|
||||
&i.AverageTimePassing,
|
||||
&i.SessionsCount,
|
||||
&i.Utm,
|
||||
&i.Rules,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -1468,7 +1622,7 @@ func (q *Queries) GetQuizConfig(ctx context.Context, id int64) (GetQuizConfigRow
|
||||
}
|
||||
|
||||
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 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, utm, rules 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
|
||||
`
|
||||
@ -1524,6 +1678,8 @@ func (q *Queries) GetQuizHistory(ctx context.Context, arg GetQuizHistoryParams)
|
||||
&i.AnswersCount,
|
||||
&i.AverageTimePassing,
|
||||
&i.SessionsCount,
|
||||
&i.Utm,
|
||||
&i.Rules,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1600,6 +1756,114 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getStepsWithPagination = `-- name: GetStepsWithPagination :many
|
||||
SELECT id, amoid, pipelineid, accountid, name, color, deleted, createdat, COUNT(*) OVER() as total_count FROM steps WHERE Deleted = false ORDER BY ID OFFSET ($1 - 1) * $2 LIMIT $2
|
||||
`
|
||||
|
||||
type GetStepsWithPaginationParams struct {
|
||||
Column1 interface{} `db:"column_1" json:"column_1"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
}
|
||||
|
||||
type GetStepsWithPaginationRow struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
Pipelineid int32 `db:"pipelineid" json:"pipelineid"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPaginationParams) ([]GetStepsWithPaginationRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getStepsWithPagination, arg.Column1, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetStepsWithPaginationRow
|
||||
for rows.Next() {
|
||||
var i GetStepsWithPaginationRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Pipelineid,
|
||||
&i.Accountid,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); 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 getTagsWithPagination = `-- name: GetTagsWithPagination :many
|
||||
SELECT id, amoid, accountid, entity, name, color, deleted, createdat, COUNT(*) OVER() as total_count FROM tags WHERE Deleted = false ORDER BY ID OFFSET ($1 - 1) * $2 LIMIT $2
|
||||
`
|
||||
|
||||
type GetTagsWithPaginationParams struct {
|
||||
Column1 interface{} `db:"column_1" json:"column_1"`
|
||||
Limit int32 `db:"limit" json:"limit"`
|
||||
}
|
||||
|
||||
type GetTagsWithPaginationRow struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Amoid int32 `db:"amoid" json:"amoid"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
Entity interface{} `db:"entity" json:"entity"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Color string `db:"color" json:"color"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
TotalCount int64 `db:"total_count" json:"total_count"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTagsWithPagination(ctx context.Context, arg GetTagsWithPaginationParams) ([]GetTagsWithPaginationRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getTagsWithPagination, arg.Column1, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetTagsWithPaginationRow
|
||||
for rows.Next() {
|
||||
var i GetTagsWithPaginationRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Accountid,
|
||||
&i.Entity,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); 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 getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
||||
SELECT id, accountid, amoid, name, email, role, "Group", deleted, createdat, subdomain, amouserid, country, COUNT(*) OVER() as total_count FROM users WHERE Deleted = false ORDER BY ID OFFSET ($1 - 1) * $2 LIMIT $2
|
||||
`
|
||||
@ -1617,7 +1881,7 @@ type GetUsersWithPaginationRow struct {
|
||||
Email string `db:"email" json:"email"`
|
||||
Role string `db:"role" json:"role"`
|
||||
Group pqtype.NullRawMessage `db:"Group" json:"Group"`
|
||||
Deleted sql.NullBool `db:"deleted" json:"deleted"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
Subdomain string `db:"subdomain" json:"subdomain"`
|
||||
Amouserid int32 `db:"amouserid" json:"amouserid"`
|
||||
@ -2250,7 +2514,7 @@ SET
|
||||
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
|
||||
(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, utm, rules 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
|
||||
|
Loading…
Reference in New Issue
Block a user