update sqlc gen
This commit is contained in:
parent
c23fda5f3f
commit
6982631f2a
@ -134,7 +134,6 @@ SELECT
|
|||||||
p.amount,
|
p.amount,
|
||||||
p.created_at,
|
p.created_at,
|
||||||
a.id,
|
a.id,
|
||||||
a.email,
|
|
||||||
qz.config
|
qz.config
|
||||||
FROM
|
FROM
|
||||||
privileges AS p
|
privileges AS p
|
||||||
@ -144,7 +143,7 @@ WHERE
|
|||||||
qz.id = $1;
|
qz.id = $1;
|
||||||
|
|
||||||
-- name: CreateAccount :one
|
-- name: CreateAccount :one
|
||||||
INSERT INTO account (id, user_id, email, created_at, deleted) VALUES ($1, $2, $3, $4, $5) RETURNING *;;
|
INSERT INTO account (id, user_id, created_at, deleted) VALUES ($1, $2, $3, $4) RETURNING *;
|
||||||
|
|
||||||
-- name: DeletePrivilegeByAccID :exec
|
-- name: DeletePrivilegeByAccID :exec
|
||||||
DELETE FROM privileges WHERE account_id = $1;
|
DELETE FROM privileges WHERE account_id = $1;
|
||||||
@ -248,7 +247,6 @@ UPDATE privileges SET amount = $1 WHERE id = $2;
|
|||||||
SELECT
|
SELECT
|
||||||
a.id,
|
a.id,
|
||||||
a.user_id,
|
a.user_id,
|
||||||
a.email,
|
|
||||||
a.created_at,
|
a.created_at,
|
||||||
COALESCE(p.ID,0),
|
COALESCE(p.ID,0),
|
||||||
coalesce(p.privilegeid,''),
|
coalesce(p.privilegeid,''),
|
||||||
|
@ -206,29 +206,29 @@ WITH user_data AS (
|
|||||||
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||||
), new_fields AS (
|
), new_fields AS (
|
||||||
SELECT (field->>'AmoID')::INT AS amoID,
|
SELECT (field->>'AmoID')::INT AS amoID,
|
||||||
COALESCE(field->>'Code', '')::varchar(255) AS code,
|
COALESCE(field->>'Code', '')::varchar(255) AS code,
|
||||||
COALESCE(field->>'Name', '')::varchar(512) AS name,
|
COALESCE(field->>'Name', '')::varchar(512) AS name,
|
||||||
CAST(field->>'Entity' AS entitytype) AS Entity,
|
CAST(field->>'Entity' AS entitytype) AS Entity,
|
||||||
COALESCE(field->>'Type', '')::fieldtype AS type,
|
COALESCE(field->>'Type', '')::fieldtype AS type,
|
||||||
CURRENT_TIMESTAMP AS createdAt
|
CURRENT_TIMESTAMP AS createdAt
|
||||||
FROM json_array_elements($2::json) AS field
|
FROM json_array_elements($2::json) AS field
|
||||||
), inserted_fields AS(
|
), inserted_fields AS(
|
||||||
INSERT INTO fields (amoID, code, accountID, name, Entity, type, createdAt)
|
INSERT INTO fields (amoID, code, accountID, name, Entity, type, createdAt)
|
||||||
SELECT nf.amoID,
|
SELECT nf.amoID,
|
||||||
nf.code,
|
nf.code,
|
||||||
ud.AmoID,
|
ud.AmoID,
|
||||||
nf.name,
|
nf.name,
|
||||||
nf.Entity,
|
nf.Entity,
|
||||||
nf.type,
|
nf.type,
|
||||||
nf.createdAt
|
nf.createdAt
|
||||||
FROM new_fields nf
|
FROM new_fields nf
|
||||||
JOIN user_data ud ON true
|
JOIN user_data ud ON true
|
||||||
ON CONFLICT (amoID, accountID, entity) DO NOTHING
|
ON CONFLICT (amoID, accountID, entity) DO NOTHING
|
||||||
RETURNING id, amoid, code, accountid, name, entity, type, deleted, createdat
|
RETURNING id, amoid, code, accountid, name, entity, type, deleted, createdat
|
||||||
)
|
)
|
||||||
SELECT nf.amoid, nf.code, nf.name, nf.entity, nf.type, nf.createdat,ud.AmoID
|
SELECT nf.amoid, nf.code, nf.name, nf.entity, nf.type, nf.createdat,ud.AmoID
|
||||||
FROM new_fields nf
|
FROM new_fields nf
|
||||||
JOIN user_data ud ON true
|
JOIN user_data ud ON true
|
||||||
WHERE NOT EXISTS (
|
WHERE NOT EXISTS (
|
||||||
SELECT id, ins.amoid, code, accountid, name, entity, type, deleted, createdat, ud.amoid
|
SELECT id, ins.amoid, code, accountid, name, entity, type, deleted, createdat, ud.amoid
|
||||||
FROM inserted_fields ins
|
FROM inserted_fields ins
|
||||||
@ -293,14 +293,14 @@ WITH new_pipelines AS (
|
|||||||
FROM json_array_elements($1::json) AS pipeline
|
FROM json_array_elements($1::json) AS pipeline
|
||||||
), inserted_pipelines AS(
|
), inserted_pipelines AS(
|
||||||
INSERT INTO pipelines (amoID, accountID, name, isArchive, createdAt)
|
INSERT INTO pipelines (amoID, accountID, name, isArchive, createdAt)
|
||||||
SELECT np.amoID,
|
SELECT np.amoID,
|
||||||
np.accountID,
|
np.accountID,
|
||||||
np.name,
|
np.name,
|
||||||
np.isArchive,
|
np.isArchive,
|
||||||
np.createdAt
|
np.createdAt
|
||||||
FROM new_pipelines np
|
FROM new_pipelines np
|
||||||
ON CONFLICT (amoID, accountID) DO NOTHING
|
ON CONFLICT (amoID, accountID) DO NOTHING
|
||||||
RETURNING id, amoid, accountid, name, isarchive, deleted, createdat
|
RETURNING id, amoid, accountid, name, isarchive, deleted, createdat
|
||||||
)
|
)
|
||||||
SELECT np.amoid, np.accountid, np.name, np.isarchive, np.createdat
|
SELECT np.amoid, np.accountid, np.name, np.isarchive, np.createdat
|
||||||
FROM new_pipelines np
|
FROM new_pipelines np
|
||||||
@ -405,15 +405,15 @@ WITH new_steps AS (
|
|||||||
FROM json_array_elements($1::json) AS step
|
FROM json_array_elements($1::json) AS step
|
||||||
), inserted_steps AS (
|
), inserted_steps AS (
|
||||||
INSERT INTO steps (amoID, pipelineID, accountID, name, color, createdAt)
|
INSERT INTO steps (amoID, pipelineID, accountID, name, color, createdAt)
|
||||||
SELECT ns.amoID,
|
SELECT ns.amoID,
|
||||||
ns.pipelineID,
|
ns.pipelineID,
|
||||||
ns.accountID,
|
ns.accountID,
|
||||||
ns.name,
|
ns.name,
|
||||||
ns.color,
|
ns.color,
|
||||||
ns.createdAt
|
ns.createdAt
|
||||||
FROM new_steps ns
|
FROM new_steps ns
|
||||||
ON CONFLICT (amoID, accountID, PipelineID) DO NOTHING
|
ON CONFLICT (amoID, accountID, PipelineID) DO NOTHING
|
||||||
RETURNING id, amoid, pipelineid, accountid, name, color, deleted, createdat
|
RETURNING id, amoid, pipelineid, accountid, name, color, deleted, createdat
|
||||||
)
|
)
|
||||||
SELECT ns.amoid, ns.pipelineid, ns.accountid, ns.name, ns.color, ns.createdat
|
SELECT ns.amoid, ns.pipelineid, ns.accountid, ns.name, ns.color, ns.createdat
|
||||||
FROM new_steps ns
|
FROM new_steps ns
|
||||||
@ -487,7 +487,7 @@ WITH user_data AS (
|
|||||||
)
|
)
|
||||||
SELECT nt.amoid, nt.entity, nt.name, nt.color,ud.AmoID
|
SELECT nt.amoid, nt.entity, nt.name, nt.color,ud.AmoID
|
||||||
FROM new_tags nt
|
FROM new_tags nt
|
||||||
JOIN user_data ud ON true
|
JOIN user_data ud ON true
|
||||||
WHERE NOT EXISTS (
|
WHERE NOT EXISTS (
|
||||||
SELECT id, ins.amoid, accountid, entity, name, color, deleted, createdat, ud.amoid
|
SELECT id, ins.amoid, accountid, entity, name, color, deleted, createdat, ud.amoid
|
||||||
FROM inserted_tags ins
|
FROM inserted_tags ins
|
||||||
@ -546,7 +546,7 @@ INSERT INTO question(
|
|||||||
SELECT $1, title, description, questiontype, required,
|
SELECT $1, title, description, questiontype, required,
|
||||||
page, content, version, parent_ids
|
page, content, version, parent_ids
|
||||||
FROM question WHERE question.id=$2
|
FROM question WHERE question.id=$2
|
||||||
RETURNING question.id, quiz_id, created_at, updated_at
|
RETURNING question.id, quiz_id, created_at, updated_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type CopyQuestionParams struct {
|
type CopyQuestionParams struct {
|
||||||
@ -578,12 +578,12 @@ INSERT INTO question (
|
|||||||
quiz_id, title, description, questiontype, required,
|
quiz_id, title, description, questiontype, required,
|
||||||
page, content, version, parent_ids, created_at, updated_at
|
page, content, version, parent_ids, created_at, updated_at
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
$2, title, description, questiontype, required,
|
$2, title, description, questiontype, required,
|
||||||
page, content, version, parent_ids, created_at, updated_at
|
page, content, version, parent_ids, created_at, updated_at
|
||||||
FROM
|
FROM
|
||||||
question
|
question
|
||||||
WHERE
|
WHERE
|
||||||
question.quiz_id = $1 AND deleted = false
|
question.quiz_id = $1 AND deleted = false
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -605,7 +605,7 @@ INSERT INTO quiz(
|
|||||||
SELECT accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
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, super, group_id
|
status,limit_answers,due_to,time_of_passing,pausable,version,version_comment,parent_ids,questions_count, super, group_id
|
||||||
FROM quiz WHERE quiz.id=$1 AND quiz.accountId=$2
|
FROM quiz WHERE quiz.id=$1 AND quiz.accountId=$2
|
||||||
RETURNING id, qid,created_at, updated_at
|
RETURNING id, qid,created_at, updated_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type CopyQuizParams struct {
|
type CopyQuizParams struct {
|
||||||
@ -1061,7 +1061,7 @@ INSERT INTO question(
|
|||||||
SELECT quiz_id, title, description, questiontype, required,
|
SELECT quiz_id, title, description, questiontype, required,
|
||||||
page, content, version, parent_ids
|
page, content, version, parent_ids
|
||||||
FROM question WHERE question.id=$1
|
FROM question WHERE question.id=$1
|
||||||
RETURNING question.id, quiz_id, created_at, updated_at
|
RETURNING question.id, quiz_id, created_at, updated_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type DuplicateQuestionRow struct {
|
type DuplicateQuestionRow struct {
|
||||||
@ -1088,13 +1088,13 @@ WITH TimeBucket AS (
|
|||||||
SELECT
|
SELECT
|
||||||
date_trunc('hour', timestamp_bucket)::TIMESTAMP AS time_interval_start,
|
date_trunc('hour', timestamp_bucket)::TIMESTAMP AS time_interval_start,
|
||||||
COALESCE(LEAD(
|
COALESCE(LEAD(
|
||||||
date_trunc('hour', timestamp_bucket)::TIMESTAMP
|
date_trunc('hour', timestamp_bucket)::TIMESTAMP
|
||||||
) OVER (ORDER BY timestamp_bucket), NOW()) AS time_interval_end
|
) OVER (ORDER BY timestamp_bucket), NOW()) AS time_interval_end
|
||||||
FROM
|
FROM
|
||||||
generate_series(TO_TIMESTAMP($1), TO_TIMESTAMP($2), CASE
|
generate_series(TO_TIMESTAMP($1), TO_TIMESTAMP($2), CASE
|
||||||
WHEN EXTRACT(epoch FROM TO_TIMESTAMP($2)) - EXTRACT(epoch FROM TO_TIMESTAMP($1)) > 172800 THEN '1 day'::interval
|
WHEN EXTRACT(epoch FROM TO_TIMESTAMP($2)) - EXTRACT(epoch FROM TO_TIMESTAMP($1)) > 172800 THEN '1 day'::interval
|
||||||
ELSE '1 hour'::interval
|
ELSE '1 hour'::interval
|
||||||
END) AS timestamp_bucket
|
END) AS timestamp_bucket
|
||||||
),
|
),
|
||||||
OpenStats AS (
|
OpenStats AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -1175,7 +1175,7 @@ SELECT
|
|||||||
CASE
|
CASE
|
||||||
WHEN COALESCE(os.open_count, 0) > 0 THEN COALESCE(rs.true_result_count, 0)::float / COALESCE(os.open_count, 0)::float
|
WHEN COALESCE(os.open_count, 0) > 0 THEN COALESCE(rs.true_result_count, 0)::float / COALESCE(os.open_count, 0)::float
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END::float AS conversion,
|
END::float AS conversion,
|
||||||
COALESCE(at.avg_time, 0) AS avg_time
|
COALESCE(at.avg_time, 0) AS avg_time
|
||||||
FROM
|
FROM
|
||||||
TimeBucket tb
|
TimeBucket tb
|
||||||
@ -2837,11 +2837,11 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
|||||||
|
|
||||||
const gettingAmoUsersTrueResults = `-- name: GettingAmoUsersTrueResults :many
|
const gettingAmoUsersTrueResults = `-- name: GettingAmoUsersTrueResults :many
|
||||||
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,
|
SELECT a.quiz_id,a.id,a.result,a.question_id,a.content,a.session,
|
||||||
COALESCE((SELECT a2.utm
|
COALESCE((SELECT a2.utm
|
||||||
FROM answer a2
|
FROM answer a2
|
||||||
WHERE a2.start = true AND a2.session = a.session
|
WHERE a2.start = true AND a2.session = a.session
|
||||||
LIMIT 1), '{}'::jsonb) AS utm
|
LIMIT 1), '{}'::jsonb) AS utm
|
||||||
,t.accesstoken,r.accountid,r.fieldsrule,r.tagstoadd,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM usersAmo u WHERE u.AmoUserID = r.performerid AND u.deleted = false) AS performer_name,u.subdomain,u.accountid,u.driveurl
|
,t.accesstoken,r.accountid,r.fieldsrule,r.tagstoadd,r.performerid,r.stepid,r.pipelineid,(SELECT u.name FROM usersAmo u WHERE u.AmoUserID = r.performerid AND u.deleted = false) AS performer_name,u.subdomain,u.accountid,u.driveurl
|
||||||
FROM answer a
|
FROM answer a
|
||||||
INNER JOIN quiz q ON a.quiz_id = q.id
|
INNER JOIN quiz q ON a.quiz_id = q.id
|
||||||
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
LEFT JOIN amoCRMStatuses s ON a.id = s.AnswerID
|
||||||
@ -3050,7 +3050,7 @@ INSERT INTO question (
|
|||||||
updated_at
|
updated_at
|
||||||
)
|
)
|
||||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)
|
||||||
RETURNING id, created_at, updated_at
|
RETURNING id, created_at, updated_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type InsertQuestionParams struct {
|
type InsertQuestionParams struct {
|
||||||
@ -3110,7 +3110,7 @@ INSERT INTO quiz (accountid,
|
|||||||
qid
|
qid
|
||||||
)
|
)
|
||||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19)
|
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
|
RETURNING id, created_at, updated_at, qid
|
||||||
`
|
`
|
||||||
|
|
||||||
type InsertQuizParams struct {
|
type InsertQuizParams struct {
|
||||||
@ -3182,7 +3182,7 @@ INSERT INTO question(
|
|||||||
SELECT quiz_id, title, description, questiontype, required,
|
SELECT quiz_id, title, description, questiontype, required,
|
||||||
page, content, version, parent_ids, true as deleted
|
page, content, version, parent_ids, true as deleted
|
||||||
FROM question WHERE question.id=$1
|
FROM question WHERE question.id=$1
|
||||||
RETURNING question.id, quiz_id, parent_ids
|
RETURNING question.id, quiz_id, parent_ids
|
||||||
`
|
`
|
||||||
|
|
||||||
type MoveToHistoryRow struct {
|
type MoveToHistoryRow struct {
|
||||||
@ -3206,7 +3206,7 @@ INSERT INTO quiz(deleted,
|
|||||||
SELECT true as deleted, accountid, archived,fingerprinting,repeatable,note_prevented,mail_notifications,unique_answers,name,description,config,
|
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
|
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
|
FROM quiz WHERE quiz.id=$1 AND quiz.accountid=$2
|
||||||
RETURNING quiz.id, qid, parent_ids
|
RETURNING quiz.id, qid, parent_ids
|
||||||
`
|
`
|
||||||
|
|
||||||
type MoveToHistoryQuizParams struct {
|
type MoveToHistoryQuizParams struct {
|
||||||
@ -3230,10 +3230,10 @@ func (q *Queries) MoveToHistoryQuiz(ctx context.Context, arg MoveToHistoryQuizPa
|
|||||||
const questionsStatistics = `-- name: QuestionsStatistics :many
|
const questionsStatistics = `-- name: QuestionsStatistics :many
|
||||||
WITH Funnel AS (
|
WITH Funnel AS (
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(DISTINCT a.session) FILTER (WHERE a.start = FALSE) AS count_start_false,
|
COUNT(DISTINCT a.session) FILTER (WHERE a.start = FALSE) AS count_start_false,
|
||||||
COUNT(DISTINCT a.session) FILTER (WHERE a.start = TRUE) AS count_start_true,
|
COUNT(DISTINCT a.session) FILTER (WHERE a.start = TRUE) AS count_start_true,
|
||||||
COUNT(DISTINCT CASE WHEN a.result = FALSE AND qid_true_result IS NOT NULL THEN a.session END) AS count_f_result_with_t_question,
|
COUNT(DISTINCT CASE WHEN a.result = FALSE AND qid_true_result IS NOT NULL THEN a.session END) AS count_f_result_with_t_question,
|
||||||
COUNT(DISTINCT a.session) FILTER (WHERE a.result = TRUE) AS count_t_result
|
COUNT(DISTINCT a.session) FILTER (WHERE a.result = TRUE) AS count_t_result
|
||||||
FROM
|
FROM
|
||||||
answer a
|
answer a
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
@ -3248,23 +3248,23 @@ WITH Funnel AS (
|
|||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
AND a.created_at <= TO_TIMESTAMP($3)
|
||||||
),
|
),
|
||||||
Results AS (
|
Results AS (
|
||||||
SELECT
|
SELECT
|
||||||
COALESCE(q.title, '') AS question_title,
|
COALESCE(q.title, '') AS question_title,
|
||||||
COUNT(*) AS total_answers,
|
COUNT(*) AS total_answers,
|
||||||
CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS FLOAT8) AS percentage
|
CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS FLOAT8) AS percentage
|
||||||
FROM
|
FROM
|
||||||
question q
|
question q
|
||||||
JOIN answer a ON q.id = a.question_id
|
JOIN answer a ON q.id = a.question_id
|
||||||
WHERE
|
WHERE
|
||||||
a.quiz_id = $1
|
a.quiz_id = $1
|
||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
AND a.created_at >= TO_TIMESTAMP($2)
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
AND a.created_at <= TO_TIMESTAMP($3)
|
||||||
AND a.result = TRUE
|
AND a.result = TRUE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
q.title, a.quiz_id, a.result
|
q.title, a.quiz_id, a.result
|
||||||
HAVING
|
HAVING
|
||||||
COUNT(*) >= 1
|
COUNT(*) >= 1
|
||||||
),
|
),
|
||||||
LastContent AS (
|
LastContent AS (
|
||||||
SELECT
|
SELECT
|
||||||
a.question_id,
|
a.question_id,
|
||||||
@ -3280,35 +3280,35 @@ WITH Funnel AS (
|
|||||||
answer
|
answer
|
||||||
WHERE
|
WHERE
|
||||||
quiz_id = $1
|
quiz_id = $1
|
||||||
AND start != true
|
AND start != true
|
||||||
AND created_at >= TO_TIMESTAMP($2)
|
AND created_at >= TO_TIMESTAMP($2)
|
||||||
AND created_at <= TO_TIMESTAMP($3)
|
AND created_at <= TO_TIMESTAMP($3)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
question_id, session
|
question_id, session
|
||||||
) AS last_created_at_one_session ON a.session = last_created_at_one_session.session AND a.question_id = last_created_at_one_session.question_id AND a.created_at = last_created_at_one_session.last_created_at
|
) AS last_created_at_one_session ON a.session = last_created_at_one_session.session AND a.question_id = last_created_at_one_session.question_id AND a.created_at = last_created_at_one_session.last_created_at
|
||||||
),
|
),
|
||||||
Questions AS (
|
Questions AS (
|
||||||
SELECT
|
SELECT
|
||||||
q.title AS question_title,
|
q.title AS question_title,
|
||||||
q.page AS question_page,
|
q.page AS question_page,
|
||||||
lc.last_answer_content AS answer_content,
|
lc.last_answer_content AS answer_content,
|
||||||
CAST(
|
CAST(
|
||||||
COUNT(CASE WHEN a.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
|
COUNT(CASE WHEN a.result = FALSE THEN 1 END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = FALSE THEN 1 END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
|
||||||
) AS percentage
|
) AS percentage
|
||||||
FROM
|
FROM
|
||||||
question q
|
question q
|
||||||
JOIN LastContent lc ON q.id = lc.question_id
|
JOIN LastContent lc ON q.id = lc.question_id
|
||||||
JOIN answer a ON q.id = a.question_id
|
JOIN answer a ON q.id = a.question_id
|
||||||
WHERE
|
WHERE
|
||||||
a.quiz_id = $1
|
a.quiz_id = $1
|
||||||
AND a.start != true
|
AND a.start != true
|
||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
AND a.created_at >= TO_TIMESTAMP($2)
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
AND a.created_at <= TO_TIMESTAMP($3)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
q.id, q.title, lc.last_answer_content
|
q.id, q.title, lc.last_answer_content
|
||||||
HAVING
|
HAVING
|
||||||
COUNT(*) >= 1
|
COUNT(*) >= 1
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
Funnel.count_start_false,
|
Funnel.count_start_false,
|
||||||
Funnel.count_start_true,
|
Funnel.count_start_true,
|
||||||
@ -3322,8 +3322,8 @@ SELECT
|
|||||||
COALESCE(Questions.percentage, 0) AS questions_percentage
|
COALESCE(Questions.percentage, 0) AS questions_percentage
|
||||||
FROM
|
FROM
|
||||||
Funnel
|
Funnel
|
||||||
LEFT JOIN Results ON true
|
LEFT JOIN Results ON true
|
||||||
LEFT JOIN Questions ON Questions.percentage >= 1
|
LEFT JOIN Questions ON Questions.percentage >= 1
|
||||||
`
|
`
|
||||||
|
|
||||||
type QuestionsStatisticsParams struct {
|
type QuestionsStatisticsParams struct {
|
||||||
@ -3380,18 +3380,18 @@ func (q *Queries) QuestionsStatistics(ctx context.Context, arg QuestionsStatisti
|
|||||||
}
|
}
|
||||||
|
|
||||||
const quizCopyQid = `-- name: QuizCopyQid :one
|
const quizCopyQid = `-- name: QuizCopyQid :one
|
||||||
INSERT INTO quiz (
|
INSERT INTO quiz (
|
||||||
accountid, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, name, description, config,
|
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
|
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
|
SELECT
|
||||||
$2, archived, fingerprinting, repeatable, note_prevented, mail_notifications, unique_answers, name, description, config,
|
$2, 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
|
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
|
FROM
|
||||||
quiz as q
|
quiz as q
|
||||||
WHERE
|
WHERE
|
||||||
q.qid = $1
|
q.qid = $1
|
||||||
RETURNING (select id from quiz where qid = $1),id, qid
|
RETURNING (select id from quiz where qid = $1),id, qid
|
||||||
`
|
`
|
||||||
|
|
||||||
type QuizCopyQidParams struct {
|
type QuizCopyQidParams struct {
|
||||||
@ -3416,7 +3416,7 @@ const setQuizSettings = `-- name: SetQuizSettings :one
|
|||||||
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule,TagsToAdd)
|
INSERT INTO rules (AccountID, QuizID, PerformerID, PipelineID, StepID, FieldsRule,TagsToAdd)
|
||||||
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
SELECT u.AmoID AS AccountID,$1 AS QuizID,$2 AS PerformerID,$3 AS PipelineID,
|
||||||
$4 AS StepID,$5 AS FieldsRule,$6 AS TagsToAdd FROM accountsamo u WHERE u.AccountID = $7 AND u.Deleted = false
|
$4 AS StepID,$5 AS FieldsRule,$6 AS TagsToAdd FROM accountsamo u WHERE u.AccountID = $7 AND u.Deleted = false
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`
|
`
|
||||||
|
|
||||||
type SetQuizSettingsParams struct {
|
type SetQuizSettingsParams struct {
|
||||||
@ -3473,10 +3473,10 @@ const softDeleteAccount = `-- name: SoftDeleteAccount :exec
|
|||||||
WITH amoCompany AS (
|
WITH amoCompany AS (
|
||||||
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1
|
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1
|
||||||
),usersDel AS (
|
),usersDel AS (
|
||||||
UPDATE usersAmo SET Deleted = true WHERE AmoID = (SELECT AmoID FROM amoCompany)
|
UPDATE usersAmo SET Deleted = true WHERE AmoID = (SELECT AmoID FROM amoCompany)
|
||||||
),
|
),
|
||||||
companyDel AS ( UPDATE accountsAmo SET Deleted = true WHERE AmoID = (SELECT AmoID FROM amoCompany)
|
companyDel AS ( UPDATE accountsAmo SET Deleted = true WHERE AmoID = (SELECT AmoID FROM amoCompany)
|
||||||
)
|
)
|
||||||
DELETE FROM tokens WHERE tokens.AccountID = $1
|
DELETE FROM tokens WHERE tokens.AccountID = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -3741,9 +3741,9 @@ const webhookDelete = `-- name: WebhookDelete :exec
|
|||||||
WITH companyDel AS (
|
WITH companyDel AS (
|
||||||
UPDATE accountsAmo SET Deleted = true WHERE accountsAmo.AmoID = $1 RETURNING AccountID
|
UPDATE accountsAmo SET Deleted = true WHERE accountsAmo.AmoID = $1 RETURNING AccountID
|
||||||
),
|
),
|
||||||
userDel AS (
|
userDel AS (
|
||||||
UPDATE usersAmo SET Deleted = true WHERE AmoID = $1
|
UPDATE usersAmo SET Deleted = true WHERE AmoID = $1
|
||||||
)
|
)
|
||||||
DELETE FROM tokens WHERE AccountID IN (SELECT AccountID FROM companyDel)
|
DELETE FROM tokens WHERE AccountID IN (SELECT AccountID FROM companyDel)
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -3827,11 +3827,11 @@ SET
|
|||||||
answers_count = COALESCE(aa.unique_true_answers_count, 0),
|
answers_count = COALESCE(aa.unique_true_answers_count, 0),
|
||||||
average_time_passing = COALESCE(sta.average_session_time, 0),
|
average_time_passing = COALESCE(sta.average_session_time, 0),
|
||||||
sessions_count = COALESCE(sta.sess,0)
|
sessions_count = COALESCE(sta.sess,0)
|
||||||
FROM
|
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 FROM quiz WHERE deleted = FALSE AND archived = FALSE) q_sub
|
||||||
LEFT JOIN answer_aggregates aa ON q_sub.id = aa.quiz_id
|
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 question_aggregates qa ON q_sub.id = qa.quiz_id
|
||||||
LEFT JOIN session_times_aggregates sta ON q_sub.id = sta.quiz_id
|
LEFT JOIN session_times_aggregates sta ON q_sub.id = sta.quiz_id
|
||||||
WHERE
|
WHERE
|
||||||
q.id = q_sub.id
|
q.id = q_sub.id
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user