sqlc gen
This commit is contained in:
parent
f48c0b89c0
commit
0529ec6ca0
@ -167,6 +167,7 @@ type Gigachataudience struct {
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type Leadtarget struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
@ -222,6 +223,7 @@ type Question struct {
|
||||
CreatedAt sql.NullTime `db:"created_at" json:"created_at"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
Session string `db:"session" json:"session"`
|
||||
Auditory sql.NullInt64 `db:"auditory" json:"auditory"`
|
||||
}
|
||||
|
||||
type Quiz struct {
|
||||
@ -256,6 +258,17 @@ type Quiz struct {
|
||||
SessionsCount sql.NullInt32 `db:"sessions_count" json:"sessions_count"`
|
||||
}
|
||||
|
||||
type RespondentState struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
TelegramID int32 `db:"telegram_id" json:"telegram_id"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
State int64 `db:"state" json:"state"`
|
||||
Lang string `db:"lang" json:"lang"`
|
||||
Contact string `db:"contact" json:"contact"`
|
||||
Finish bool `db:"finish" json:"finish"`
|
||||
Session sql.NullString `db:"session" json:"session"`
|
||||
}
|
||||
|
||||
type Rule struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid int32 `db:"accountid" json:"accountid"`
|
||||
@ -305,6 +318,37 @@ type Tag struct {
|
||||
Createdat sql.NullTime `db:"createdat" json:"createdat"`
|
||||
}
|
||||
|
||||
type TelegramIntegration struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Quizid int32 `db:"quizid" json:"quizid"`
|
||||
BotToken string `db:"bot_token" json:"bot_token"`
|
||||
BotName string `db:"bot_name" json:"bot_name"`
|
||||
Repeatable sql.NullBool `db:"repeatable" json:"repeatable"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Status interface{} `db:"status" json:"status"`
|
||||
InstanceID int32 `db:"instance_id" json:"instance_id"`
|
||||
}
|
||||
|
||||
type TelegramIntegrationInstance struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Checkout int64 `db:"checkout" json:"checkout"`
|
||||
Limited int32 `db:"limited" json:"limited"`
|
||||
Amount int32 `db:"amount" json:"amount"`
|
||||
}
|
||||
|
||||
type TelegramUserQuizResult struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
BotID int64 `db:"bot_id" json:"bot_id"`
|
||||
QuizID int64 `db:"quiz_id" json:"quiz_id"`
|
||||
CurrentField sql.NullString `db:"current_field" json:"current_field"`
|
||||
UserAnswer sql.NullString `db:"user_answer" json:"user_answer"`
|
||||
State interface{} `db:"state" json:"state"`
|
||||
Session string `db:"session" json:"session"`
|
||||
QuestionID int64 `db:"question_id" json:"question_id"`
|
||||
Iter int32 `db:"iter" json:"iter"`
|
||||
}
|
||||
|
||||
type Tgaccount struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Apiid int32 `db:"apiid" json:"apiid"`
|
||||
|
@ -1078,7 +1078,6 @@ func (q *Queries) CreateAmoAccount(ctx context.Context, arg CreateAmoAccountPara
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
const createBitrixAccount = `-- name: CreateBitrixAccount :exec
|
||||
INSERT INTO BitrixAccounts (AccountID, BitrixID, Subdomain)
|
||||
VALUES ($1, $2, $3)
|
||||
@ -1100,10 +1099,6 @@ INSERT INTO BitrixTokens (AccountID, RefreshToken, AccessToken, AuthCode, Expira
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
const createQuizAudience = `-- name: CreateQuizAudience :one
|
||||
INSERT INTO gigachatAudience (QuizID, Sex, Age) VALUES ($1, $2, $3) RETURNING ID
|
||||
`
|
||||
|
||||
type CreateBitrixWebHookParams struct {
|
||||
Accountid string `db:"accountid" json:"accountid"`
|
||||
Refreshtoken string `db:"refreshtoken" json:"refreshtoken"`
|
||||
@ -1159,6 +1154,23 @@ func (q *Queries) CreateLeadTarget(ctx context.Context, arg CreateLeadTargetPara
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createQuizAudience = `-- name: CreateQuizAudience :one
|
||||
INSERT INTO gigachatAudience (QuizID, Sex, Age) VALUES ($1, $2, $3) RETURNING ID
|
||||
`
|
||||
|
||||
type CreateQuizAudienceParams struct {
|
||||
Quizid int64 `db:"quizid" json:"quizid"`
|
||||
Sex bool `db:"sex" json:"sex"`
|
||||
Age string `db:"age" json:"age"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateQuizAudience(ctx context.Context, arg CreateQuizAudienceParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, createQuizAudience, arg.Quizid, arg.Sex, arg.Age)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createTgAccount = `-- name: CreateTgAccount :one
|
||||
INSERT INTO tgAccounts (ApiID, ApiHash, PhoneNumber,Password, Status)
|
||||
VALUES ($1, $2, $3, $4, $5) RETURNING id
|
||||
@ -1327,7 +1339,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.session
|
||||
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.session, question.auditory
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error) {
|
||||
@ -1348,6 +1360,7 @@ func (q *Queries) DeleteQuestion(ctx context.Context, id int64) (Question, error
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -2878,7 +2891,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, session 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, session, auditory 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
|
||||
`
|
||||
@ -2913,6 +2926,7 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2928,7 +2942,7 @@ func (q *Queries) GetQuestionHistory(ctx context.Context, arg GetQuestionHistory
|
||||
}
|
||||
|
||||
const getQuestionListByIDs = `-- name: GetQuestionListByIDs :many
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session FROM question WHERE id = ANY($1::int[]) AND deleted = FALSE
|
||||
SELECT id, quiz_id, title, description, questiontype, required, deleted, page, content, version, parent_ids, created_at, updated_at, session, auditory FROM question WHERE id = ANY($1::int[]) AND deleted = FALSE
|
||||
`
|
||||
|
||||
func (q *Queries) GetQuestionListByIDs(ctx context.Context, dollar_1 []int32) ([]Question, error) {
|
||||
@ -2955,6 +2969,7 @@ func (q *Queries) GetQuestionListByIDs(ctx context.Context, dollar_1 []int32) ([
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Session,
|
||||
&i.Auditory,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -3059,7 +3074,24 @@ type GetQuestionsAIParams struct {
|
||||
Offset int32 `db:"offset" json:"offset"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) ([]Question, error) {
|
||||
type GetQuestionsAIRow 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"`
|
||||
Session string `db:"session" json:"session"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) ([]GetQuestionsAIRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getQuestionsAI,
|
||||
arg.QuizID,
|
||||
arg.Session,
|
||||
@ -3070,9 +3102,9 @@ func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams)
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Question
|
||||
var items []GetQuestionsAIRow
|
||||
for rows.Next() {
|
||||
var i Question
|
||||
var i GetQuestionsAIRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.QuizID,
|
||||
@ -3903,19 +3935,6 @@ func (q *Queries) GetUserUsersByID(ctx context.Context, amoid int32) ([]Usersamo
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getUsersCount = `-- name: GetUsersCount :one
|
||||
WITH user_data AS (
|
||||
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||
)
|
||||
SELECT COUNT(*) FROM usersAmo u JOIN user_data a ON u.AmoID = a.AmoID WHERE u.Deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersCount(ctx context.Context, accountid string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUsersCount, accountid)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
const getUserUsersByIDBitrix = `-- name: GetUserUsersByIDBitrix :many
|
||||
SELECT id, accountid, bitrixiduserid, name, lastname, secondname, title, email, ufdepartment, workposition, deleted, createdat FROM BitrixAccountUsers WHERE accountID = $1 AND Deleted = false
|
||||
`
|
||||
@ -4028,6 +4047,19 @@ func (q *Queries) GetUsersBitrixWithPagination(ctx context.Context, arg GetUsers
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getUsersCount = `-- name: GetUsersCount :one
|
||||
WITH user_data AS (
|
||||
SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false
|
||||
)
|
||||
SELECT COUNT(*) FROM usersAmo u JOIN user_data a ON u.AmoID = a.AmoID WHERE u.Deleted = false
|
||||
`
|
||||
|
||||
func (q *Queries) GetUsersCount(ctx context.Context, accountid string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUsersCount, accountid)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const getUsersWithPagination = `-- name: GetUsersWithPagination :many
|
||||
WITH user_data AS (
|
||||
@ -4052,11 +4084,10 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetUsersWithPaginationRow
|
||||
var items []Usersamo
|
||||
for rows.Next() {
|
||||
var i GetUsersWithPaginationRow
|
||||
var i Usersamo
|
||||
if err := rows.Scan(
|
||||
&i.QuizID,
|
||||
&i.ID,
|
||||
&i.Amoid,
|
||||
&i.Amouserid,
|
||||
@ -4066,7 +4097,6 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa
|
||||
&i.Group,
|
||||
&i.Deleted,
|
||||
&i.Createdat,
|
||||
&i.TotalCount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -4405,9 +4435,10 @@ INSERT INTO question (
|
||||
content,
|
||||
parent_ids,
|
||||
updated_at,
|
||||
session
|
||||
session,
|
||||
auditory
|
||||
)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)
|
||||
RETURNING id, created_at, updated_at
|
||||
`
|
||||
|
||||
@ -4422,6 +4453,7 @@ type InsertQuestionParams struct {
|
||||
ParentIds []int32 `db:"parent_ids" json:"parent_ids"`
|
||||
UpdatedAt sql.NullTime `db:"updated_at" json:"updated_at"`
|
||||
Session string `db:"session" json:"session"`
|
||||
Auditory sql.NullInt64 `db:"auditory" json:"auditory"`
|
||||
}
|
||||
|
||||
type InsertQuestionRow struct {
|
||||
@ -4442,6 +4474,7 @@ func (q *Queries) InsertQuestion(ctx context.Context, arg InsertQuestionParams)
|
||||
pq.Array(arg.ParentIds),
|
||||
arg.UpdatedAt,
|
||||
arg.Session,
|
||||
arg.Auditory,
|
||||
)
|
||||
var i InsertQuestionRow
|
||||
err := row.Scan(&i.ID, &i.CreatedAt, &i.UpdatedAt)
|
||||
@ -4615,14 +4648,14 @@ SELECT
|
||||
CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS FLOAT8) AS percentage
|
||||
FROM
|
||||
question q
|
||||
LEFT JOIN QuizAnswers a ON q.id = a.question_id
|
||||
JOIN answer a ON q.id = a.question_id
|
||||
WHERE
|
||||
a.quiz_id = $1
|
||||
AND a.created_at >= TO_TIMESTAMP($2)
|
||||
AND a.created_at <= TO_TIMESTAMP($3)
|
||||
AND a.result = TRUE
|
||||
GROUP BY
|
||||
q.title, a.result, a.quiz_id
|
||||
q.title, a.quiz_id, a.result
|
||||
HAVING
|
||||
COUNT(*) >= 1
|
||||
),
|
||||
@ -4648,9 +4681,7 @@ SELECT
|
||||
AND created_at <= TO_TIMESTAMP($3)
|
||||
GROUP BY
|
||||
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 (
|
||||
SELECT
|
||||
@ -4698,16 +4729,16 @@ type QuestionsStatisticsParams struct {
|
||||
}
|
||||
|
||||
type QuestionsStatisticsRow struct {
|
||||
CountStartFalse int64 `db:"count_start_false" json:"count_start_false"`
|
||||
CountStartTrue int64 `db:"count_start_true" json:"count_start_true"`
|
||||
CountFResultWithTQuestion int64 `db:"count_f_result_with_t_question" json:"count_f_result_with_t_question"`
|
||||
CountTResult int64 `db:"count_t_result" json:"count_t_result"`
|
||||
ResultsTitle string `db:"results_title" json:"results_title"`
|
||||
ResultsPercentage float64 `db:"results_percentage" json:"results_percentage"`
|
||||
QuestionsTitle string `db:"questions_title" json:"questions_title"`
|
||||
QuestionsPage interface{} `db:"questions_page" json:"questions_page"`
|
||||
AnswerContent string `db:"answer_content" json:"answer_content"`
|
||||
QuestionsPercentage float64 `db:"questions_percentage" json:"questions_percentage"`
|
||||
CountStartFalse int64 `db:"count_start_false" json:"count_start_false"`
|
||||
CountStartTrue int64 `db:"count_start_true" json:"count_start_true"`
|
||||
CountFResultWithTQuestion int64 `db:"count_f_result_with_t_question" json:"count_f_result_with_t_question"`
|
||||
CountTResult int64 `db:"count_t_result" json:"count_t_result"`
|
||||
ResultsTitle string `db:"results_title" json:"results_title"`
|
||||
ResultsPercentage float64 `db:"results_percentage" json:"results_percentage"`
|
||||
QuestionsTitle string `db:"questions_title" json:"questions_title"`
|
||||
QuestionsPage int16 `db:"questions_page" json:"questions_page"`
|
||||
AnswerContent string `db:"answer_content" json:"answer_content"`
|
||||
QuestionsPercentage float64 `db:"questions_percentage" json:"questions_percentage"`
|
||||
}
|
||||
|
||||
func (q *Queries) QuestionsStatistics(ctx context.Context, arg QuestionsStatisticsParams) ([]QuestionsStatisticsRow, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user