// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: user.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const BulkDeactivateUsersByRole = `-- name: BulkDeactivateUsersByRole :execrows UPDATE users SET status = 'DEACTIVATED', updated_at = CURRENT_TIMESTAMP WHERE role = $1 AND id <> $2 AND status <> 'DEACTIVATED' ` type BulkDeactivateUsersByRoleParams struct { Role string `json:"role"` ID int64 `json:"id"` } func (q *Queries) BulkDeactivateUsersByRole(ctx context.Context, arg BulkDeactivateUsersByRoleParams) (int64, error) { result, err := q.db.Exec(ctx, BulkDeactivateUsersByRole, arg.Role, arg.ID) if err != nil { return 0, err } return result.RowsAffected(), nil } const BulkReactivateUsersByRole = `-- name: BulkReactivateUsersByRole :execrows UPDATE users SET status = 'ACTIVE', updated_at = CURRENT_TIMESTAMP WHERE role = $1 AND id <> $2 AND status = 'DEACTIVATED' ` type BulkReactivateUsersByRoleParams struct { Role string `json:"role"` ID int64 `json:"id"` } func (q *Queries) BulkReactivateUsersByRole(ctx context.Context, arg BulkReactivateUsersByRoleParams) (int64, error) { result, err := q.db.Exec(ctx, BulkReactivateUsersByRole, arg.Role, arg.ID) if err != nil { return 0, err } return result.RowsAffected(), nil } const CheckPhoneEmailExist = `-- name: CheckPhoneEmailExist :one SELECT EXISTS ( SELECT 1 FROM users u1 WHERE $1::TEXT IS NOT NULL AND TRIM($1::TEXT) <> '' AND u1.phone_number IS NOT NULL AND TRIM(u1.phone_number) = TRIM($1::TEXT) ) AS phone_exists, EXISTS ( SELECT 1 FROM users u2 WHERE $2::TEXT IS NOT NULL AND TRIM($2::TEXT) <> '' AND u2.email IS NOT NULL AND LOWER(TRIM(u2.email)) = LOWER(TRIM($2::TEXT)) ) AS email_exists ` type CheckPhoneEmailExistParams struct { PhoneNumber pgtype.Text `json:"phone_number"` Email pgtype.Text `json:"email"` } type CheckPhoneEmailExistRow struct { PhoneExists bool `json:"phone_exists"` EmailExists bool `json:"email_exists"` } func (q *Queries) CheckPhoneEmailExist(ctx context.Context, arg CheckPhoneEmailExistParams) (CheckPhoneEmailExistRow, error) { row := q.db.QueryRow(ctx, CheckPhoneEmailExist, arg.PhoneNumber, arg.Email) var i CheckPhoneEmailExistRow err := row.Scan(&i.PhoneExists, &i.EmailExists) return i, err } const CreateAppleUser = `-- name: CreateAppleUser :one INSERT INTO users ( first_name, last_name, email, apple_id, apple_email_verified, role, status, email_verified ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8 ) RETURNING id, first_name, last_name, gender, birth_day, email, phone_number, role, password, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at, age_group, google_id, google_email_verified, profile_completion_percentage, deletion_requested_at, deletion_scheduled_at, deletion_cancelled_at, apple_id, apple_email_verified ` type CreateAppleUserParams struct { FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Email pgtype.Text `json:"email"` AppleID pgtype.Text `json:"apple_id"` AppleEmailVerified pgtype.Bool `json:"apple_email_verified"` Role string `json:"role"` Status string `json:"status"` EmailVerified bool `json:"email_verified"` } func (q *Queries) CreateAppleUser(ctx context.Context, arg CreateAppleUserParams) (User, error) { row := q.db.QueryRow(ctx, CreateAppleUser, arg.FirstName, arg.LastName, arg.Email, arg.AppleID, arg.AppleEmailVerified, arg.Role, arg.Status, arg.EmailVerified, ) var i User err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, &i.AgeGroup, &i.GoogleID, &i.GoogleEmailVerified, &i.ProfileCompletionPercentage, &i.DeletionRequestedAt, &i.DeletionScheduledAt, &i.DeletionCancelledAt, &i.AppleID, &i.AppleEmailVerified, ) return i, err } const CreateGoogleUser = `-- name: CreateGoogleUser :one INSERT INTO users ( first_name, last_name, email, google_id, google_email_verified, role, status, email_verified, profile_picture_url ) VALUES ( $1, $2, $3, $4, $5, $6, $7, true, $8 ) RETURNING id, first_name, last_name, gender, birth_day, email, phone_number, role, password, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at, age_group, google_id, google_email_verified, profile_completion_percentage, deletion_requested_at, deletion_scheduled_at, deletion_cancelled_at, apple_id, apple_email_verified ` type CreateGoogleUserParams struct { FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Email pgtype.Text `json:"email"` GoogleID pgtype.Text `json:"google_id"` GoogleEmailVerified pgtype.Bool `json:"google_email_verified"` Role string `json:"role"` Status string `json:"status"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` } func (q *Queries) CreateGoogleUser(ctx context.Context, arg CreateGoogleUserParams) (User, error) { row := q.db.QueryRow(ctx, CreateGoogleUser, arg.FirstName, arg.LastName, arg.Email, arg.GoogleID, arg.GoogleEmailVerified, arg.Role, arg.Status, arg.ProfilePictureUrl, ) var i User err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, &i.AgeGroup, &i.GoogleID, &i.GoogleEmailVerified, &i.ProfileCompletionPercentage, &i.DeletionRequestedAt, &i.DeletionScheduledAt, &i.DeletionCancelledAt, &i.AppleID, &i.AppleEmailVerified, ) return i, err } const CreateUser = `-- name: CreateUser :one INSERT INTO users ( first_name, last_name, gender, birth_day, email, phone_number, role, password, age_group, education_level, country, region, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, profile_completed, profile_picture_url, preferred_language, updated_at ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, -- age_group $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, CURRENT_TIMESTAMP ) RETURNING id, first_name, last_name, gender, birth_day, email, phone_number, role, age_group, education_level, country, region, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, profile_completed, profile_completion_percentage, profile_picture_url, preferred_language, created_at, updated_at ` type CreateUserParams struct { FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Gender pgtype.Text `json:"gender"` BirthDay pgtype.Date `json:"birth_day"` Email pgtype.Text `json:"email"` PhoneNumber pgtype.Text `json:"phone_number"` Role string `json:"role"` Password []byte `json:"password"` AgeGroup pgtype.Text `json:"age_group"` EducationLevel pgtype.Text `json:"education_level"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` NickName pgtype.Text `json:"nick_name"` Occupation pgtype.Text `json:"occupation"` LearningGoal pgtype.Text `json:"learning_goal"` LanguageGoal pgtype.Text `json:"language_goal"` LanguageChallange pgtype.Text `json:"language_challange"` FavouriteTopic pgtype.Text `json:"favourite_topic"` EmailVerified bool `json:"email_verified"` PhoneVerified bool `json:"phone_verified"` Status string `json:"status"` ProfileCompleted pgtype.Bool `json:"profile_completed"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` PreferredLanguage pgtype.Text `json:"preferred_language"` } type CreateUserRow struct { ID int64 `json:"id"` FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Gender pgtype.Text `json:"gender"` BirthDay pgtype.Date `json:"birth_day"` Email pgtype.Text `json:"email"` PhoneNumber pgtype.Text `json:"phone_number"` Role string `json:"role"` AgeGroup pgtype.Text `json:"age_group"` EducationLevel pgtype.Text `json:"education_level"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` NickName pgtype.Text `json:"nick_name"` Occupation pgtype.Text `json:"occupation"` LearningGoal pgtype.Text `json:"learning_goal"` LanguageGoal pgtype.Text `json:"language_goal"` LanguageChallange pgtype.Text `json:"language_challange"` FavouriteTopic pgtype.Text `json:"favourite_topic"` EmailVerified bool `json:"email_verified"` PhoneVerified bool `json:"phone_verified"` Status string `json:"status"` ProfileCompleted pgtype.Bool `json:"profile_completed"` ProfileCompletionPercentage int16 `json:"profile_completion_percentage"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` PreferredLanguage pgtype.Text `json:"preferred_language"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) { row := q.db.QueryRow(ctx, CreateUser, arg.FirstName, arg.LastName, arg.Gender, arg.BirthDay, arg.Email, arg.PhoneNumber, arg.Role, arg.Password, arg.AgeGroup, arg.EducationLevel, arg.Country, arg.Region, arg.NickName, arg.Occupation, arg.LearningGoal, arg.LanguageGoal, arg.LanguageChallange, arg.FavouriteTopic, arg.EmailVerified, arg.PhoneVerified, arg.Status, arg.ProfileCompleted, arg.ProfilePictureUrl, arg.PreferredLanguage, ) var i CreateUserRow err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.AgeGroup, &i.EducationLevel, &i.Country, &i.Region, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.ProfileCompleted, &i.ProfileCompletionPercentage, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const DeleteUser = `-- name: DeleteUser :exec DELETE FROM users WHERE id = $1 ` func (q *Queries) DeleteUser(ctx context.Context, id int64) error { _, err := q.db.Exec(ctx, DeleteUser, id) return err } const GetAllUsers = `-- name: GetAllUsers :many SELECT COUNT(*) OVER () AS total_count, id, first_name, last_name, gender, birth_day, email, phone_number, role, age_group, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_completion_percentage, profile_picture_url, preferred_language, created_at, updated_at FROM users WHERE ($1::TEXT IS NULL OR role = $1::TEXT) AND ( $2::TEXT IS NULL OR ( $2::TEXT = 'INACTIVE' AND status <> 'ACTIVE' ) OR ( $2::TEXT <> 'INACTIVE' AND status = $2::TEXT ) ) AND ($3::TEXT IS NULL OR ( first_name ILIKE '%' || $3::TEXT || '%' OR last_name ILIKE '%' || $3::TEXT || '%' OR email ILIKE '%' || $3::TEXT || '%' OR phone_number ILIKE '%' || $3::TEXT || '%' )) AND ($4::TIMESTAMPTZ IS NULL OR created_at >= $4::TIMESTAMPTZ) AND ($5::TIMESTAMPTZ IS NULL OR created_at <= $5::TIMESTAMPTZ) AND ($6::TEXT IS NULL OR LOWER(TRIM(COALESCE(country, ''))) = LOWER(TRIM($6::TEXT))) AND ($7::TEXT IS NULL OR LOWER(TRIM(COALESCE(region, ''))) = LOWER(TRIM($7::TEXT))) AND ($8::TEXT IS NULL OR LOWER(TRIM(COALESCE(education_level, ''))) = LOWER(TRIM($8::TEXT))) AND ($9::TEXT IS NULL OR LOWER(TRIM(COALESCE(occupation, ''))) = LOWER(TRIM($9::TEXT))) AND ($10::TEXT IS NULL OR LOWER(TRIM(COALESCE(age_group, ''))) = LOWER(TRIM($10::TEXT))) AND ($11::TEXT IS NULL OR LOWER(TRIM(COALESCE(favourite_topic, ''))) = LOWER(TRIM($11::TEXT))) AND ($12::TEXT IS NULL OR LOWER(TRIM(COALESCE(language_goal, ''))) = LOWER(TRIM($12::TEXT))) AND ($13::TEXT IS NULL OR LOWER(TRIM(COALESCE(learning_goal, ''))) = LOWER(TRIM($13::TEXT))) AND ($14::TEXT IS NULL OR LOWER(TRIM(COALESCE(knowledge_level, ''))) = LOWER(TRIM($14::TEXT))) AND ($15::BOOLEAN IS NULL OR profile_completed = $15::BOOLEAN) AND ( $16::INT IS NULL OR profile_completion_percentage >= $16::INT ) AND ($17::TIMESTAMPTZ IS NULL OR last_login >= $17::TIMESTAMPTZ) AND ($18::TIMESTAMPTZ IS NULL OR last_login <= $18::TIMESTAMPTZ) AND ( $19::INT IS NULL OR ( last_login IS NOT NULL AND last_login <= CURRENT_TIMESTAMP - ($19::INT || ' days')::INTERVAL ) ) AND ( $20::INT IS NULL OR ( last_login IS NOT NULL AND last_login >= CURRENT_TIMESTAMP - ($20::INT || ' days')::INTERVAL ) ) AND ( $21::INT IS NULL OR ( SELECT COUNT(*)::INT FROM lms_user_lesson_progress ulp WHERE ulp.user_id = users.id ) >= $21::INT ) AND ( $22::INT IS NULL OR ( SELECT COUNT(*)::INT FROM lms_user_module_progress ump WHERE ump.user_id = users.id ) >= $22::INT ) AND ( $23::BOOLEAN IS NULL OR ( $23::BOOLEAN = TRUE AND EXISTS ( SELECT 1 FROM payments p WHERE p.user_id = users.id AND p.status = 'SUCCESS' ) ) OR ( $23::BOOLEAN = FALSE AND NOT EXISTS ( SELECT 1 FROM payments p WHERE p.user_id = users.id AND p.status = 'SUCCESS' ) ) ) AND ( $24::BOOLEAN IS NULL OR EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP AND us.auto_renew = $24::BOOLEAN ) ) AND ( $25::BIGINT IS NULL OR EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP AND us.plan_id = $25::BIGINT ) ) AND ( $26::TEXT IS NULL OR EXISTS ( SELECT 1 FROM user_subscriptions us JOIN subscription_plans sp ON sp.id = us.plan_id WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP AND UPPER(TRIM(sp.category)) = UPPER(TRIM($26::TEXT)) ) ) AND ( $27::INT IS NULL OR EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP AND us.expires_at <= CURRENT_TIMESTAMP + ($27::INT || ' days')::INTERVAL ) ) AND ( $28::TEXT IS NULL OR EXISTS ( SELECT 1 FROM devices d WHERE d.user_id = users.id AND d.is_active = TRUE AND LOWER(TRIM(COALESCE(d.platform, ''))) = LOWER(TRIM($28::TEXT)) ) ) AND ( $29::BOOLEAN IS NULL OR ( $29::BOOLEAN = TRUE AND EXISTS ( SELECT 1 FROM devices d WHERE d.user_id = users.id AND d.is_active = TRUE AND TRIM(COALESCE(d.device_token, '')) <> '' ) ) OR ( $29::BOOLEAN = FALSE AND NOT EXISTS ( SELECT 1 FROM devices d WHERE d.user_id = users.id AND d.is_active = TRUE AND TRIM(COALESCE(d.device_token, '')) <> '' ) ) ) AND ( $30::TEXT IS NULL OR ( $30::TEXT = 'ACTIVE' AND EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP ) ) OR ( $30::TEXT = 'PENDING' AND NOT EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP ) AND EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'PENDING' ) ) OR ( $30::TEXT = 'Unsubscribed' AND NOT EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP ) ) OR ( $30::TEXT = 'EXPIRED' AND NOT EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'ACTIVE' AND us.expires_at > CURRENT_TIMESTAMP ) AND NOT EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND us.status = 'PENDING' ) AND EXISTS ( SELECT 1 FROM user_subscriptions us WHERE us.user_id = users.id AND ( us.status = 'EXPIRED' OR us.status = 'CANCELLED' OR (us.expires_at <= CURRENT_TIMESTAMP AND us.status <> 'PENDING') ) ) ) ) ORDER BY created_at DESC LIMIT $32::INT OFFSET $31::INT ` type GetAllUsersParams struct { Role pgtype.Text `json:"role"` Status pgtype.Text `json:"status"` Query pgtype.Text `json:"query"` CreatedAfter pgtype.Timestamptz `json:"created_after"` CreatedBefore pgtype.Timestamptz `json:"created_before"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` EducationLevel pgtype.Text `json:"education_level"` Occupation pgtype.Text `json:"occupation"` AgeGroup pgtype.Text `json:"age_group"` FavouriteTopic pgtype.Text `json:"favourite_topic"` LanguageGoal pgtype.Text `json:"language_goal"` LearningGoal pgtype.Text `json:"learning_goal"` KnowledgeLevel pgtype.Text `json:"knowledge_level"` ProfileCompleted pgtype.Bool `json:"profile_completed"` MinProfileCompletionPct pgtype.Int4 `json:"min_profile_completion_pct"` LastLoginAfter pgtype.Timestamptz `json:"last_login_after"` LastLoginBefore pgtype.Timestamptz `json:"last_login_before"` DaysSinceLastLoginMin pgtype.Int4 `json:"days_since_last_login_min"` DaysSinceLastLoginMax pgtype.Int4 `json:"days_since_last_login_max"` MinLessonsCompleted pgtype.Int4 `json:"min_lessons_completed"` MinModulesCompleted pgtype.Int4 `json:"min_modules_completed"` HasEverPaid pgtype.Bool `json:"has_ever_paid"` AutoRenew pgtype.Bool `json:"auto_renew"` PlanID pgtype.Int8 `json:"plan_id"` PlanCategory pgtype.Text `json:"plan_category"` ExpiresWithinDays pgtype.Int4 `json:"expires_within_days"` DevicePlatform pgtype.Text `json:"device_platform"` HasActiveDevice pgtype.Bool `json:"has_active_device"` SubscriptionStatus pgtype.Text `json:"subscription_status"` Offset pgtype.Int4 `json:"offset"` Limit pgtype.Int4 `json:"limit"` } type GetAllUsersRow struct { TotalCount int64 `json:"total_count"` ID int64 `json:"id"` FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Gender pgtype.Text `json:"gender"` BirthDay pgtype.Date `json:"birth_day"` Email pgtype.Text `json:"email"` PhoneNumber pgtype.Text `json:"phone_number"` Role string `json:"role"` AgeGroup pgtype.Text `json:"age_group"` EducationLevel pgtype.Text `json:"education_level"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` KnowledgeLevel pgtype.Text `json:"knowledge_level"` NickName pgtype.Text `json:"nick_name"` Occupation pgtype.Text `json:"occupation"` LearningGoal pgtype.Text `json:"learning_goal"` LanguageGoal pgtype.Text `json:"language_goal"` LanguageChallange pgtype.Text `json:"language_challange"` FavouriteTopic pgtype.Text `json:"favourite_topic"` EmailVerified bool `json:"email_verified"` PhoneVerified bool `json:"phone_verified"` Status string `json:"status"` LastLogin pgtype.Timestamptz `json:"last_login"` ProfileCompleted pgtype.Bool `json:"profile_completed"` ProfileCompletionPercentage int16 `json:"profile_completion_percentage"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` PreferredLanguage pgtype.Text `json:"preferred_language"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) GetAllUsers(ctx context.Context, arg GetAllUsersParams) ([]GetAllUsersRow, error) { rows, err := q.db.Query(ctx, GetAllUsers, arg.Role, arg.Status, arg.Query, arg.CreatedAfter, arg.CreatedBefore, arg.Country, arg.Region, arg.EducationLevel, arg.Occupation, arg.AgeGroup, arg.FavouriteTopic, arg.LanguageGoal, arg.LearningGoal, arg.KnowledgeLevel, arg.ProfileCompleted, arg.MinProfileCompletionPct, arg.LastLoginAfter, arg.LastLoginBefore, arg.DaysSinceLastLoginMin, arg.DaysSinceLastLoginMax, arg.MinLessonsCompleted, arg.MinModulesCompleted, arg.HasEverPaid, arg.AutoRenew, arg.PlanID, arg.PlanCategory, arg.ExpiresWithinDays, arg.DevicePlatform, arg.HasActiveDevice, arg.SubscriptionStatus, arg.Offset, arg.Limit, ) if err != nil { return nil, err } defer rows.Close() var items []GetAllUsersRow for rows.Next() { var i GetAllUsersRow if err := rows.Scan( &i.TotalCount, &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.AgeGroup, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfileCompletionPercentage, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetProfileCompletionStatus = `-- name: GetProfileCompletionStatus :one SELECT profile_completed, profile_completion_percentage FROM users WHERE id = $1 LIMIT 1 ` type GetProfileCompletionStatusRow struct { ProfileCompleted pgtype.Bool `json:"profile_completed"` ProfileCompletionPercentage int16 `json:"profile_completion_percentage"` } func (q *Queries) GetProfileCompletionStatus(ctx context.Context, id int64) (GetProfileCompletionStatusRow, error) { row := q.db.QueryRow(ctx, GetProfileCompletionStatus, id) var i GetProfileCompletionStatusRow err := row.Scan(&i.ProfileCompleted, &i.ProfileCompletionPercentage) return i, err } const GetTotalUsers = `-- name: GetTotalUsers :one SELECT COUNT(*) FROM users WHERE (role = $1 OR $1 IS NULL) ` func (q *Queries) GetTotalUsers(ctx context.Context, role string) (int64, error) { row := q.db.QueryRow(ctx, GetTotalUsers, role) var count int64 err := row.Scan(&count) return count, err } const GetUserByAppleID = `-- name: GetUserByAppleID :one SELECT id, first_name, last_name, gender, birth_day, email, phone_number, role, password, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at, age_group, google_id, google_email_verified, profile_completion_percentage, deletion_requested_at, deletion_scheduled_at, deletion_cancelled_at, apple_id, apple_email_verified FROM users WHERE apple_id = $1 ` func (q *Queries) GetUserByAppleID(ctx context.Context, appleID pgtype.Text) (User, error) { row := q.db.QueryRow(ctx, GetUserByAppleID, appleID) var i User err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, &i.AgeGroup, &i.GoogleID, &i.GoogleEmailVerified, &i.ProfileCompletionPercentage, &i.DeletionRequestedAt, &i.DeletionScheduledAt, &i.DeletionCancelledAt, &i.AppleID, &i.AppleEmailVerified, ) return i, err } const GetUserByEmailPhone = `-- name: GetUserByEmailPhone :one SELECT id, first_name, last_name, gender, birth_day, email, phone_number, role, password, age_group, education_level, country, region, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, profile_completed, profile_completion_percentage, last_login, profile_picture_url, preferred_language, created_at, updated_at FROM users WHERE ( $1::TEXT IS NOT NULL AND TRIM($1::TEXT) <> '' AND LOWER(TRIM(email)) = LOWER(TRIM($1::TEXT)) ) OR ( $2::TEXT IS NOT NULL AND TRIM($2::TEXT) <> '' AND TRIM(phone_number) = TRIM($2::TEXT) ) LIMIT 1 ` type GetUserByEmailPhoneParams struct { Email pgtype.Text `json:"email"` PhoneNumber pgtype.Text `json:"phone_number"` } type GetUserByEmailPhoneRow struct { ID int64 `json:"id"` FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Gender pgtype.Text `json:"gender"` BirthDay pgtype.Date `json:"birth_day"` Email pgtype.Text `json:"email"` PhoneNumber pgtype.Text `json:"phone_number"` Role string `json:"role"` Password []byte `json:"password"` AgeGroup pgtype.Text `json:"age_group"` EducationLevel pgtype.Text `json:"education_level"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` NickName pgtype.Text `json:"nick_name"` Occupation pgtype.Text `json:"occupation"` LearningGoal pgtype.Text `json:"learning_goal"` LanguageGoal pgtype.Text `json:"language_goal"` LanguageChallange pgtype.Text `json:"language_challange"` FavouriteTopic pgtype.Text `json:"favourite_topic"` EmailVerified bool `json:"email_verified"` PhoneVerified bool `json:"phone_verified"` Status string `json:"status"` ProfileCompleted pgtype.Bool `json:"profile_completed"` ProfileCompletionPercentage int16 `json:"profile_completion_percentage"` LastLogin pgtype.Timestamptz `json:"last_login"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` PreferredLanguage pgtype.Text `json:"preferred_language"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` } // -- name: GetUserByUserName :one // SELECT // // id, // first_name, // last_name, // email, // phone_number, // role, // password, // age, // education_level, // country, // region, // nick_name, // occupation, // learning_goal, // language_goal, // language_challange, // favourite_topic, // email_verified, // phone_verified, // status, // profile_completed, // last_login, // profile_picture_url, // preferred_language, // created_at, // updated_at // // FROM users // WHERE user_name = $1 AND $1 IS NOT NULL // LIMIT 1; func (q *Queries) GetUserByEmailPhone(ctx context.Context, arg GetUserByEmailPhoneParams) (GetUserByEmailPhoneRow, error) { row := q.db.QueryRow(ctx, GetUserByEmailPhone, arg.Email, arg.PhoneNumber) var i GetUserByEmailPhoneRow err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.AgeGroup, &i.EducationLevel, &i.Country, &i.Region, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.ProfileCompleted, &i.ProfileCompletionPercentage, &i.LastLogin, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const GetUserByGoogleID = `-- name: GetUserByGoogleID :one SELECT id, first_name, last_name, gender, birth_day, email, phone_number, role, password, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at, age_group, google_id, google_email_verified, profile_completion_percentage, deletion_requested_at, deletion_scheduled_at, deletion_cancelled_at, apple_id, apple_email_verified FROM users WHERE google_id = $1 ` func (q *Queries) GetUserByGoogleID(ctx context.Context, googleID pgtype.Text) (User, error) { row := q.db.QueryRow(ctx, GetUserByGoogleID, googleID) var i User err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, &i.AgeGroup, &i.GoogleID, &i.GoogleEmailVerified, &i.ProfileCompletionPercentage, &i.DeletionRequestedAt, &i.DeletionScheduledAt, &i.DeletionCancelledAt, &i.AppleID, &i.AppleEmailVerified, ) return i, err } const GetUserByID = `-- name: GetUserByID :one SELECT id, first_name, last_name, gender, birth_day, email, phone_number, role, password, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at, age_group, google_id, google_email_verified, profile_completion_percentage, deletion_requested_at, deletion_scheduled_at, deletion_cancelled_at, apple_id, apple_email_verified FROM users WHERE id = $1 ` func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) { row := q.db.QueryRow(ctx, GetUserByID, id) var i User err := row.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, &i.AgeGroup, &i.GoogleID, &i.GoogleEmailVerified, &i.ProfileCompletionPercentage, &i.DeletionRequestedAt, &i.DeletionScheduledAt, &i.DeletionCancelledAt, &i.AppleID, &i.AppleEmailVerified, ) return i, err } const GetUserCreatedAt = `-- name: GetUserCreatedAt :one SELECT created_at FROM users WHERE id = $1 ` func (q *Queries) GetUserCreatedAt(ctx context.Context, id int64) (pgtype.Timestamptz, error) { row := q.db.QueryRow(ctx, GetUserCreatedAt, id) var created_at pgtype.Timestamptz err := row.Scan(&created_at) return created_at, err } const GetUserSummary = `-- name: GetUserSummary :one SELECT COUNT(*) AS total_users, COUNT(*) FILTER (WHERE status = 'ACTIVE') AS active_users, COUNT(*) FILTER (WHERE created_at >= date_trunc('month', CURRENT_DATE)) AS joined_this_month FROM users ` type GetUserSummaryRow struct { TotalUsers int64 `json:"total_users"` ActiveUsers int64 `json:"active_users"` JoinedThisMonth int64 `json:"joined_this_month"` } func (q *Queries) GetUserSummary(ctx context.Context) (GetUserSummaryRow, error) { row := q.db.QueryRow(ctx, GetUserSummary) var i GetUserSummaryRow err := row.Scan(&i.TotalUsers, &i.ActiveUsers, &i.JoinedThisMonth) return i, err } const GetUsersByIDs = `-- name: GetUsersByIDs :many SELECT id, first_name, last_name, gender, birth_day, email, phone_number, role, password, education_level, country, region, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at, age_group, google_id, google_email_verified, profile_completion_percentage, deletion_requested_at, deletion_scheduled_at, deletion_cancelled_at, apple_id, apple_email_verified FROM users WHERE id = ANY($1::BIGINT[]) ` func (q *Queries) GetUsersByIDs(ctx context.Context, dollar_1 []int64) ([]User, error) { rows, err := q.db.Query(ctx, GetUsersByIDs, dollar_1) if err != nil { return nil, err } defer rows.Close() var items []User for rows.Next() { var i User if err := rows.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.Password, &i.EducationLevel, &i.Country, &i.Region, &i.KnowledgeLevel, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.LastLogin, &i.ProfileCompleted, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.CreatedAt, &i.UpdatedAt, &i.AgeGroup, &i.GoogleID, &i.GoogleEmailVerified, &i.ProfileCompletionPercentage, &i.DeletionRequestedAt, &i.DeletionScheduledAt, &i.DeletionCancelledAt, &i.AppleID, &i.AppleEmailVerified, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const IsUserNameUnique = `-- name: IsUserNameUnique :one SELECT CASE WHEN COUNT(*) = 0 THEN true ELSE false END AS is_unique FROM users WHERE id = $1 ` func (q *Queries) IsUserNameUnique(ctx context.Context, id int64) (bool, error) { row := q.db.QueryRow(ctx, IsUserNameUnique, id) var is_unique bool err := row.Scan(&is_unique) return is_unique, err } const IsUserPending = `-- name: IsUserPending :one SELECT CASE WHEN status = 'PENDING' THEN true ELSE false END AS is_pending FROM users WHERE id = $1 LIMIT 1 ` func (q *Queries) IsUserPending(ctx context.Context, id int64) (bool, error) { row := q.db.QueryRow(ctx, IsUserPending, id) var is_pending bool err := row.Scan(&is_pending) return is_pending, err } const LinkAppleAccount = `-- name: LinkAppleAccount :exec UPDATE users SET apple_id = $2, apple_email_verified = $3, updated_at = CURRENT_TIMESTAMP WHERE id = $1 ` type LinkAppleAccountParams struct { ID int64 `json:"id"` AppleID pgtype.Text `json:"apple_id"` AppleEmailVerified pgtype.Bool `json:"apple_email_verified"` } func (q *Queries) LinkAppleAccount(ctx context.Context, arg LinkAppleAccountParams) error { _, err := q.db.Exec(ctx, LinkAppleAccount, arg.ID, arg.AppleID, arg.AppleEmailVerified) return err } const LinkGoogleAccount = `-- name: LinkGoogleAccount :exec UPDATE users SET google_id = $2, google_email_verified = true, updated_at = CURRENT_TIMESTAMP WHERE id = $1 ` type LinkGoogleAccountParams struct { ID int64 `json:"id"` GoogleID pgtype.Text `json:"google_id"` } func (q *Queries) LinkGoogleAccount(ctx context.Context, arg LinkGoogleAccountParams) error { _, err := q.db.Exec(ctx, LinkGoogleAccount, arg.ID, arg.GoogleID) return err } const SearchUserByNameOrPhone = `-- name: SearchUserByNameOrPhone :many SELECT id, first_name, last_name, gender, birth_day, email, phone_number, role, age_group, education_level, country, region, nick_name, occupation, learning_goal, language_goal, language_challange, favourite_topic, profile_picture_url, preferred_language, email_verified, phone_verified, status, profile_completed, profile_completion_percentage, created_at, updated_at FROM users WHERE ( first_name ILIKE '%' || $1 || '%' OR last_name ILIKE '%' || $1 || '%' OR phone_number ILIKE '%' || $1 || '%' OR email ILIKE '%' || $1 || '%' ) AND ( role = $2 OR $2 IS NULL ) ` type SearchUserByNameOrPhoneParams struct { Column1 pgtype.Text `json:"column_1"` Role pgtype.Text `json:"role"` } type SearchUserByNameOrPhoneRow struct { ID int64 `json:"id"` FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` Gender pgtype.Text `json:"gender"` BirthDay pgtype.Date `json:"birth_day"` Email pgtype.Text `json:"email"` PhoneNumber pgtype.Text `json:"phone_number"` Role string `json:"role"` AgeGroup pgtype.Text `json:"age_group"` EducationLevel pgtype.Text `json:"education_level"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` NickName pgtype.Text `json:"nick_name"` Occupation pgtype.Text `json:"occupation"` LearningGoal pgtype.Text `json:"learning_goal"` LanguageGoal pgtype.Text `json:"language_goal"` LanguageChallange pgtype.Text `json:"language_challange"` FavouriteTopic pgtype.Text `json:"favourite_topic"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` PreferredLanguage pgtype.Text `json:"preferred_language"` EmailVerified bool `json:"email_verified"` PhoneVerified bool `json:"phone_verified"` Status string `json:"status"` ProfileCompleted pgtype.Bool `json:"profile_completed"` ProfileCompletionPercentage int16 `json:"profile_completion_percentage"` CreatedAt pgtype.Timestamptz `json:"created_at"` UpdatedAt pgtype.Timestamptz `json:"updated_at"` } func (q *Queries) SearchUserByNameOrPhone(ctx context.Context, arg SearchUserByNameOrPhoneParams) ([]SearchUserByNameOrPhoneRow, error) { rows, err := q.db.Query(ctx, SearchUserByNameOrPhone, arg.Column1, arg.Role) if err != nil { return nil, err } defer rows.Close() var items []SearchUserByNameOrPhoneRow for rows.Next() { var i SearchUserByNameOrPhoneRow if err := rows.Scan( &i.ID, &i.FirstName, &i.LastName, &i.Gender, &i.BirthDay, &i.Email, &i.PhoneNumber, &i.Role, &i.AgeGroup, &i.EducationLevel, &i.Country, &i.Region, &i.NickName, &i.Occupation, &i.LearningGoal, &i.LanguageGoal, &i.LanguageChallange, &i.FavouriteTopic, &i.ProfilePictureUrl, &i.PreferredLanguage, &i.EmailVerified, &i.PhoneVerified, &i.Status, &i.ProfileCompleted, &i.ProfileCompletionPercentage, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const UpdatePassword = `-- name: UpdatePassword :exec UPDATE users SET password = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2 ` type UpdatePasswordParams struct { Password []byte `json:"password"` ID int64 `json:"id"` } func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error { _, err := q.db.Exec(ctx, UpdatePassword, arg.Password, arg.ID) return err } const UpdateUser = `-- name: UpdateUser :exec UPDATE users SET first_name = COALESCE($1, first_name), last_name = COALESCE($2, last_name), knowledge_level = COALESCE($3, knowledge_level), age_group = COALESCE($4, age_group), education_level = COALESCE($5, education_level), country = COALESCE($6, country), region = COALESCE($7, region), nick_name = COALESCE($8, nick_name), occupation = COALESCE($9, occupation), learning_goal = COALESCE($10, learning_goal), language_goal = COALESCE($11, language_goal), language_challange = COALESCE($12, language_challange), favourite_topic = COALESCE($13, favourite_topic), profile_picture_url = COALESCE($14, profile_picture_url), preferred_language = COALESCE($15, preferred_language), gender = COALESCE($16, gender), birth_day = COALESCE($17, birth_day), updated_at = CURRENT_TIMESTAMP WHERE id = $18 ` type UpdateUserParams struct { FirstName pgtype.Text `json:"first_name"` LastName pgtype.Text `json:"last_name"` KnowledgeLevel pgtype.Text `json:"knowledge_level"` AgeGroup pgtype.Text `json:"age_group"` EducationLevel pgtype.Text `json:"education_level"` Country pgtype.Text `json:"country"` Region pgtype.Text `json:"region"` NickName pgtype.Text `json:"nick_name"` Occupation pgtype.Text `json:"occupation"` LearningGoal pgtype.Text `json:"learning_goal"` LanguageGoal pgtype.Text `json:"language_goal"` LanguageChallange pgtype.Text `json:"language_challange"` FavouriteTopic pgtype.Text `json:"favourite_topic"` ProfilePictureUrl pgtype.Text `json:"profile_picture_url"` PreferredLanguage pgtype.Text `json:"preferred_language"` Gender pgtype.Text `json:"gender"` BirthDay pgtype.Date `json:"birth_day"` ID int64 `json:"id"` } // Note: profile_completed and profile_completion_percentage are computed by database trigger func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error { _, err := q.db.Exec(ctx, UpdateUser, arg.FirstName, arg.LastName, arg.KnowledgeLevel, arg.AgeGroup, arg.EducationLevel, arg.Country, arg.Region, arg.NickName, arg.Occupation, arg.LearningGoal, arg.LanguageGoal, arg.LanguageChallange, arg.FavouriteTopic, arg.ProfilePictureUrl, arg.PreferredLanguage, arg.Gender, arg.BirthDay, arg.ID, ) return err } const UpdateUserKnowledgeLevel = `-- name: UpdateUserKnowledgeLevel :exec UPDATE users SET knowledge_level = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2 ` type UpdateUserKnowledgeLevelParams struct { KnowledgeLevel pgtype.Text `json:"knowledge_level"` ID int64 `json:"id"` } func (q *Queries) UpdateUserKnowledgeLevel(ctx context.Context, arg UpdateUserKnowledgeLevelParams) error { _, err := q.db.Exec(ctx, UpdateUserKnowledgeLevel, arg.KnowledgeLevel, arg.ID) return err } const UpdateUserStatus = `-- name: UpdateUserStatus :exec UPDATE users SET status = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2 ` type UpdateUserStatusParams struct { Status string `json:"status"` ID int64 `json:"id"` } func (q *Queries) UpdateUserStatus(ctx context.Context, arg UpdateUserStatusParams) error { _, err := q.db.Exec(ctx, UpdateUserStatus, arg.Status, arg.ID) return err }