Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stevenmasley/paged users#1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Emyrk wants to merge3 commits intomainfromstevenmasley/paged_users
Closed
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
User pagination unit testing
  • Loading branch information
@Emyrk
Emyrk committedApr 18, 2022
commitcbd7cebaa7baeaf912df8ef2d770abe2fef27164
6 changes: 5 additions & 1 deletioncoderd/database/databasefake/databasefake.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1375,6 +1375,10 @@ func (q *fakeQuerier) DeleteGitSSHKey(_ context.Context, userID uuid.UUID) error
return sql.ErrNoRows
}

func (q *fakeQuerier) PaginatedUsers(ctx context.Context, arg database.PaginatedUsersParams) ([]database.User, error) {
func (q *fakeQuerier) PaginatedUsersAfter(ctx context.Context, arg database.PaginatedUsersAfterParams) ([]database.User, error) {
return nil, xerrors.Errorf("not implemented")
}

func (q *fakeQuerier) PaginatedUsersBefore(ctx context.Context, arg database.PaginatedUsersBeforeParams) ([]database.User, error) {
return nil, xerrors.Errorf("not implemented")
}
3 changes: 2 additions & 1 deletioncoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

90 changes: 81 additions & 9 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

46 changes: 38 additions & 8 deletionscoderd/database/queries/users.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,7 +53,7 @@ WHERE
id = $1 RETURNING *;


-- name:PaginatedUsers :many
-- name:PaginatedUsersAfter :many
SELECT
*
FROM
Expand All@@ -62,15 +62,45 @@ WHERE
CASE
WHEN @after::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
created_at > (SELECT created_at FROM users WHERE id = @after)
WHEN @before::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
created_at < (SELECT created_at FROM users WHERE id = @before)
ELSE true
-- If the after field is not provided, just return the first page
ELSE true
END
AND
CASE
WHEN @email::text != '' THEN
email LIKE '%' || @email || '%'
ELSE true
END
ORDER BY
-- TODO: When doing 'before', we need to flip this to DESC.
-- You cannot put 'ASC' or 'DESC' in a CASE statement. :'(
-- Until we figure this out, before is broken.
-- Another option is to do a subquery above
created_at ASC
LIMIT
@limit_opt;

-- name: PaginatedUsersBefore :many
SELECT users_before.* FROM
(SELECT
*
FROM
users
WHERE
CASE
WHEN @before::uuid != '00000000-0000-0000-0000-000000000000'::uuid THEN
created_at < (SELECT created_at FROM users WHERE id = @before)
-- If the 'before' field is not provided, this will return the last page.
-- Kinda odd, it's just a consequence of spliting the pagination queries into 2
-- functions.
ELSE true
END
AND
CASE
WHEN @email::text != '' THEN
email LIKE '%' || @email || '%'
ELSE true
END
ORDER BY
created_at DESC
LIMIT
@limit_opt) AS users_before
-- Maintain the original ordering of the rows so the pages are the same order
-- as PaginatedUsersAfter.
ORDER BY users_before.created_at ASC;

[8]ページ先頭

©2009-2025 Movatter.jp