diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index cba76ba..cd55627 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -771,7 +771,7 @@ ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3; WITH user_data AS ( SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false ) -SELECT COUNT(*) FROM steps s JOIN user_data u ON s.AccountID = u.AmoID WHERE s.Deleted = false AND s.PipelineID = $4; +SELECT COUNT(*) FROM steps s JOIN user_data u ON s.AccountID = u.AmoID WHERE s.Deleted = false AND s.PipelineID = $2; -- name: GetPipelinesWithPagination :many WITH user_data AS ( @@ -1087,7 +1087,7 @@ UPDATE amoContact SET Field = $1,AmoID=$3 WHERE ID = $2; -- name: GetQuestionsAI :many SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session FROM question q WHERE q.quiz_id = $1 AND (q.session = $2 OR q.session = '') AND q.deleted = FALSE -ORDER BY q.page, q.created_at ASC LIMIT $3 OFFSET $4 +ORDER BY q.page, q.created_at ASC LIMIT $3 OFFSET $4; -- name: GetQuestionsAICount :one SELECT COUNT(*) AS count FROM question WHERE quiz_id = $1 AND (session = $2 OR session = '') AND deleted = FALSE; diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index ba76f7e..5ca3fc3 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -1605,11 +1605,25 @@ func (q *Queries) GetFieldByAmoID(ctx context.Context, amoid int32) (Field, erro return i, err } +const getFieldsCount = `-- name: GetFieldsCount :one +WITH user_data AS ( + SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false +) +SELECT COUNT(*) FROM fields f JOIN user_data u ON f.AccountID = u.AmoID WHERE f.Deleted = false +` + +func (q *Queries) GetFieldsCount(ctx context.Context, accountid string) (int64, error) { + row := q.db.QueryRowContext(ctx, getFieldsCount, accountid) + var count int64 + err := row.Scan(&count) + return count, err +} + const getFieldsWithPagination = `-- name: GetFieldsWithPagination :many WITH user_data AS ( SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false ) -SELECT f.id, f.amoid, f.code, f.accountid, f.name, f.entity, f.type, f.deleted, f.createdat, COUNT(*) OVER() as total_count +SELECT f.id, f.amoid, f.code, f.accountid, f.name, f.entity, f.type, f.deleted, f.createdat FROM fields f JOIN user_data u ON f.AccountID = u.AmoID WHERE f.Deleted = false ORDER BY f.ID OFFSET ($2 - 1) * $3 LIMIT $3 @@ -1621,28 +1635,15 @@ type GetFieldsWithPaginationParams struct { 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 interface{} `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) { +func (q *Queries) GetFieldsWithPagination(ctx context.Context, arg GetFieldsWithPaginationParams) ([]Field, error) { rows, err := q.db.QueryContext(ctx, getFieldsWithPagination, arg.Accountid, arg.Column2, arg.Limit) if err != nil { return nil, err } defer rows.Close() - var items []GetFieldsWithPaginationRow + var items []Field for rows.Next() { - var i GetFieldsWithPaginationRow + var i Field if err := rows.Scan( &i.ID, &i.Amoid, @@ -1653,7 +1654,6 @@ func (q *Queries) GetFieldsWithPagination(ctx context.Context, arg GetFieldsWith &i.Type, &i.Deleted, &i.Createdat, - &i.TotalCount, ); err != nil { return nil, err } @@ -1724,11 +1724,25 @@ func (q *Queries) GetListStartQuiz(ctx context.Context, accountid string) ([]int return items, nil } +const getPipelinesCount = `-- name: GetPipelinesCount :one +WITH user_data AS ( + SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false +) +SELECT COUNT(*) FROM pipelines p JOIN user_data u ON p.AccountID = u.AmoID WHERE p.Deleted = false +` + +func (q *Queries) GetPipelinesCount(ctx context.Context, accountid string) (int64, error) { + row := q.db.QueryRowContext(ctx, getPipelinesCount, accountid) + var count int64 + err := row.Scan(&count) + return count, err +} + const getPipelinesWithPagination = `-- name: GetPipelinesWithPagination :many WITH user_data AS ( SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false ) -SELECT p.id, p.amoid, p.accountid, p.name, p.isarchive, p.deleted, p.createdat, COUNT(*) OVER() as total_count +SELECT p.id, p.amoid, p.accountid, p.name, p.isarchive, p.deleted, p.createdat FROM pipelines p JOIN user_data u ON p.AccountID = u.AmoID WHERE p.Deleted = false ORDER BY p.ID OFFSET ($2 - 1) * $3 LIMIT $3 @@ -1740,26 +1754,15 @@ type GetPipelinesWithPaginationParams struct { 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) { +func (q *Queries) GetPipelinesWithPagination(ctx context.Context, arg GetPipelinesWithPaginationParams) ([]Pipeline, error) { rows, err := q.db.QueryContext(ctx, getPipelinesWithPagination, arg.Accountid, arg.Column2, arg.Limit) if err != nil { return nil, err } defer rows.Close() - var items []GetPipelinesWithPaginationRow + var items []Pipeline for rows.Next() { - var i GetPipelinesWithPaginationRow + var i Pipeline if err := rows.Scan( &i.ID, &i.Amoid, @@ -1768,7 +1771,6 @@ func (q *Queries) GetPipelinesWithPagination(ctx context.Context, arg GetPipelin &i.Isarchive, &i.Deleted, &i.Createdat, - &i.TotalCount, ); err != nil { return nil, err } @@ -2101,10 +2103,7 @@ func (q *Queries) GetQuestions(ctx context.Context, quizID int64) ([]GetQuestion } const getQuestionsAI = `-- name: GetQuestionsAI :many -WITH total_count AS (SELECT COUNT(*) AS count -FROM question WHERE quiz_id = $1 AND (session = $2 OR session = '') AND deleted = FALSE) -SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session, t.count FROM question q - CROSS JOIN total_count t +SELECT q.id, q.quiz_id, q.title, q.description, q.questiontype, q.required, q.deleted, q.page, q.content, q.version, q.parent_ids, q.created_at, q.updated_at, q.session FROM question q WHERE q.quiz_id = $1 AND (q.session = $2 OR q.session = '') AND q.deleted = FALSE ORDER BY q.page, q.created_at ASC LIMIT $3 OFFSET $4 ` @@ -2116,25 +2115,7 @@ type GetQuestionsAIParams struct { Offset int32 `db:"offset" json:"offset"` } -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"` - Count int64 `db:"count" json:"count"` -} - -func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) ([]GetQuestionsAIRow, error) { +func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) ([]Question, error) { rows, err := q.db.QueryContext(ctx, getQuestionsAI, arg.QuizID, arg.Session, @@ -2145,9 +2126,9 @@ func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) return nil, err } defer rows.Close() - var items []GetQuestionsAIRow + var items []Question for rows.Next() { - var i GetQuestionsAIRow + var i Question if err := rows.Scan( &i.ID, &i.QuizID, @@ -2163,7 +2144,6 @@ func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) &i.CreatedAt, &i.UpdatedAt, &i.Session, - &i.Count, ); err != nil { return nil, err } @@ -2178,6 +2158,22 @@ func (q *Queries) GetQuestionsAI(ctx context.Context, arg GetQuestionsAIParams) return items, nil } +const getQuestionsAICount = `-- name: GetQuestionsAICount :one +SELECT COUNT(*) AS count FROM question WHERE quiz_id = $1 AND (session = $2 OR session = '') AND deleted = FALSE +` + +type GetQuestionsAICountParams struct { + QuizID int64 `db:"quiz_id" json:"quiz_id"` + Session string `db:"session" json:"session"` +} + +func (q *Queries) GetQuestionsAICount(ctx context.Context, arg GetQuestionsAICountParams) (int64, error) { + row := q.db.QueryRowContext(ctx, getQuestionsAICount, arg.QuizID, arg.Session) + var count int64 + err := row.Scan(&count) + return count, err +} + 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 ` @@ -2446,13 +2442,32 @@ func (q *Queries) GetResultAnswers(ctx context.Context, id int64) ([]GetResultAn return items, nil } +const getStepsCount = `-- name: GetStepsCount :one +WITH user_data AS ( + SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false +) +SELECT COUNT(*) FROM steps s JOIN user_data u ON s.AccountID = u.AmoID WHERE s.Deleted = false AND s.PipelineID = $2 +` + +type GetStepsCountParams struct { + Accountid string `db:"accountid" json:"accountid"` + Pipelineid int32 `db:"pipelineid" json:"pipelineid"` +} + +func (q *Queries) GetStepsCount(ctx context.Context, arg GetStepsCountParams) (int64, error) { + row := q.db.QueryRowContext(ctx, getStepsCount, arg.Accountid, arg.Pipelineid) + var count int64 + err := row.Scan(&count) + return count, err +} + const getStepsWithPagination = `-- name: GetStepsWithPagination :many WITH user_data AS ( SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false ) -SELECT s.id, s.amoid, s.pipelineid, s.accountid, s.name, s.color, s.deleted, s.createdat, COUNT(*) OVER() as total_count +SELECT s.id, s.amoid, s.pipelineid, s.accountid, s.name, s.color, s.deleted, s.createdat FROM steps s JOIN user_data u ON s.AccountID = u.AmoID -WHERE s.Deleted = false AND PipelineID = $4 +WHERE s.Deleted = false AND s.PipelineID = $4 ORDER BY s.ID OFFSET ($2 - 1) * $3 LIMIT $3 ` @@ -2463,19 +2478,7 @@ type GetStepsWithPaginationParams struct { Pipelineid int32 `db:"pipelineid" json:"pipelineid"` } -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) { +func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPaginationParams) ([]Step, error) { rows, err := q.db.QueryContext(ctx, getStepsWithPagination, arg.Accountid, arg.Column2, @@ -2486,9 +2489,9 @@ func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPa return nil, err } defer rows.Close() - var items []GetStepsWithPaginationRow + var items []Step for rows.Next() { - var i GetStepsWithPaginationRow + var i Step if err := rows.Scan( &i.ID, &i.Amoid, @@ -2498,7 +2501,6 @@ func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPa &i.Color, &i.Deleted, &i.Createdat, - &i.TotalCount, ); err != nil { return nil, err } @@ -2513,11 +2515,25 @@ func (q *Queries) GetStepsWithPagination(ctx context.Context, arg GetStepsWithPa return items, nil } +const getTagsCount = `-- name: GetTagsCount :one +WITH user_data AS ( + SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false +) +SELECT COUNT(*) FROM tags t JOIN user_data u ON t.AccountID = u.AmoID WHERE t.Deleted = false +` + +func (q *Queries) GetTagsCount(ctx context.Context, accountid string) (int64, error) { + row := q.db.QueryRowContext(ctx, getTagsCount, accountid) + var count int64 + err := row.Scan(&count) + return count, err +} + const getTagsWithPagination = `-- name: GetTagsWithPagination :many WITH user_data AS ( SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false ) -SELECT t.id, t.amoid, t.accountid, t.entity, t.name, t.color, t.deleted, t.createdat, COUNT(*) OVER() as total_count +SELECT t.id, t.amoid, t.accountid, t.entity, t.name, t.color, t.deleted, t.createdat FROM tags t JOIN user_data u ON t.AccountID = u.AmoID WHERE t.Deleted = false ORDER BY t.ID OFFSET ($2 - 1) * $3 LIMIT $3 @@ -2529,27 +2545,15 @@ type GetTagsWithPaginationParams struct { 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) { +func (q *Queries) GetTagsWithPagination(ctx context.Context, arg GetTagsWithPaginationParams) ([]Tag, error) { rows, err := q.db.QueryContext(ctx, getTagsWithPagination, arg.Accountid, arg.Column2, arg.Limit) if err != nil { return nil, err } defer rows.Close() - var items []GetTagsWithPaginationRow + var items []Tag for rows.Next() { - var i GetTagsWithPaginationRow + var i Tag if err := rows.Scan( &i.ID, &i.Amoid, @@ -2559,7 +2563,6 @@ func (q *Queries) GetTagsWithPagination(ctx context.Context, arg GetTagsWithPagi &i.Color, &i.Deleted, &i.Createdat, - &i.TotalCount, ); err != nil { return nil, err } @@ -2809,11 +2812,25 @@ 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 getUsersWithPagination = `-- name: GetUsersWithPagination :many WITH user_data AS ( SELECT AmoID FROM accountsAmo WHERE accountsAmo.AccountID = $1 AND accountsAmo.Deleted = false ) -SELECT u.id, u.amoid, u.amouserid, u.name, u.email, u.role, u."Group", u.deleted, u.createdat, COUNT(*) OVER() as total_count +SELECT u.id, u.amoid, u.amouserid, u.name, u.email, u.role, u."Group", u.deleted, u.createdat FROM usersAmo u JOIN user_data a ON u.AmoID = a.AmoID WHERE u.Deleted = false @@ -2826,28 +2843,15 @@ type GetUsersWithPaginationParams struct { Limit int32 `db:"limit" json:"limit"` } -type GetUsersWithPaginationRow struct { - ID int64 `db:"id" json:"id"` - Amoid int32 `db:"amoid" json:"amoid"` - Amouserid int32 `db:"amouserid" json:"amouserid"` - Name string `db:"name" json:"name"` - Email string `db:"email" json:"email"` - Role int32 `db:"role" json:"role"` - Group int32 `db:"Group" json:"Group"` - Deleted bool `db:"deleted" json:"deleted"` - Createdat time.Time `db:"createdat" json:"createdat"` - TotalCount int64 `db:"total_count" json:"total_count"` -} - -func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPaginationParams) ([]GetUsersWithPaginationRow, error) { +func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPaginationParams) ([]Usersamo, error) { rows, err := q.db.QueryContext(ctx, getUsersWithPagination, arg.Accountid, arg.Column2, arg.Limit) if err != nil { 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.ID, &i.Amoid, @@ -2858,7 +2862,6 @@ func (q *Queries) GetUsersWithPagination(ctx context.Context, arg GetUsersWithPa &i.Group, &i.Deleted, &i.Createdat, - &i.TotalCount, ); err != nil { return nil, err }