// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: users.sql package sqlc import ( "context" "database/sql" ) const countAdmins = `-- name: CountAdmins :one SELECT COUNT(*)::bigint AS count FROM users WHERE role = $1 ` func (q *Queries) CountAdmins(ctx context.Context, role string) (int64, error) { row := q.db.QueryRowContext(ctx, countAdmins, role) var count int64 err := row.Scan(&count) return count, err } const createUser = `-- name: CreateUser :exec INSERT INTO users (id, username, name, password_hash, role, email, avatar_url, state, created_at) VALUES ($1, $2, $3, $4, $5, $6, '', '', $7) ` type CreateUserParams struct { ID string Username string Name string PasswordHash string Role string Email string CreatedAt string } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) error { _, err := q.db.ExecContext(ctx, createUser, arg.ID, arg.Username, arg.Name, arg.PasswordHash, arg.Role, arg.Email, arg.CreatedAt, ) return err } const getUserByID = `-- name: GetUserByID :one SELECT id, username, name, role, email, avatar_url, state, created_at FROM users WHERE id = $1 ` type GetUserByIDRow struct { ID string Username string Name string Role string Email string AvatarUrl string State string CreatedAt string } func (q *Queries) GetUserByID(ctx context.Context, id string) (GetUserByIDRow, error) { row := q.db.QueryRowContext(ctx, getUserByID, id) var i GetUserByIDRow err := row.Scan( &i.ID, &i.Username, &i.Name, &i.Role, &i.Email, &i.AvatarUrl, &i.State, &i.CreatedAt, ) return i, err } const getUserByUsername = `-- name: GetUserByUsername :one SELECT id, username, name, role, email, avatar_url, state, created_at, password_hash FROM users WHERE username = $1 ` type GetUserByUsernameRow struct { ID string Username string Name string Role string Email string AvatarUrl string State string CreatedAt string PasswordHash string } func (q *Queries) GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error) { row := q.db.QueryRowContext(ctx, getUserByUsername, username) var i GetUserByUsernameRow err := row.Scan( &i.ID, &i.Username, &i.Name, &i.Role, &i.Email, &i.AvatarUrl, &i.State, &i.CreatedAt, &i.PasswordHash, ) return i, err } const getUserRole = `-- name: GetUserRole :one SELECT role FROM users WHERE id = $1 ` func (q *Queries) GetUserRole(ctx context.Context, id string) (string, error) { row := q.db.QueryRowContext(ctx, getUserRole, id) var role string err := row.Scan(&role) return role, err } const listUsers = `-- name: ListUsers :many SELECT id, username, name, role, email, avatar_url, state, created_at FROM users WHERE ( $1 = '' OR username ILIKE '%' || $1 || '%' OR name ILIKE '%' || $1 || '%' OR email ILIKE '%' || $1 || '%' ) AND ( $2 = '' OR created_at < $2 OR (created_at = $2 AND id < $3) ) ORDER BY created_at DESC, id DESC LIMIT $4 ` type ListUsersParams struct { Search interface{} CursorCreated interface{} CursorID string RowLimit int32 } type ListUsersRow struct { ID string Username string Name string Role string Email string AvatarUrl string State string CreatedAt string } func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]ListUsersRow, error) { rows, err := q.db.QueryContext(ctx, listUsers, arg.Search, arg.CursorCreated, arg.CursorID, arg.RowLimit, ) if err != nil { return nil, err } defer rows.Close() items := []ListUsersRow{} for rows.Next() { var i ListUsersRow if err := rows.Scan( &i.ID, &i.Username, &i.Name, &i.Role, &i.Email, &i.AvatarUrl, &i.State, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateUserProfile = `-- name: UpdateUserProfile :exec UPDATE users SET state = $1, email = $2 WHERE id = $3 ` type UpdateUserProfileParams struct { State string Email string ID string } func (q *Queries) UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) error { _, err := q.db.ExecContext(ctx, updateUserProfile, arg.State, arg.Email, arg.ID) return err } const updateUserProfileAndAvatar = `-- name: UpdateUserProfileAndAvatar :exec UPDATE users SET state = $1, email = $2, avatar_url = $3 WHERE id = $4 ` type UpdateUserProfileAndAvatarParams struct { State string Email string AvatarUrl string ID string } func (q *Queries) UpdateUserProfileAndAvatar(ctx context.Context, arg UpdateUserProfileAndAvatarParams) error { _, err := q.db.ExecContext(ctx, updateUserProfileAndAvatar, arg.State, arg.Email, arg.AvatarUrl, arg.ID, ) return err } const updateUserRole = `-- name: UpdateUserRole :execresult UPDATE users SET role = $1 WHERE id = $2 ` type UpdateUserRoleParams struct { Role string ID string } func (q *Queries) UpdateUserRole(ctx context.Context, arg UpdateUserRoleParams) (sql.Result, error) { return q.db.ExecContext(ctx, updateUserRole, arg.Role, arg.ID) }