Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit 和 firstOrNull 的逻辑似乎有点矛盾 #260

Open
swiftlei opened this issue Aug 30, 2024 · 6 comments
Open

limit 和 firstOrNull 的逻辑似乎有点矛盾 #260

swiftlei opened this issue Aug 30, 2024 · 6 comments

Comments

@swiftlei
Copy link

当执行下面的语句

.where(...)
.....
.orderBy(...)
.limit(100, 1)
.firstOrNull()

时,返回的结果总是符合查询条件的第一条记录,而不是 limit 指定的 offset 100后的第一条

如果修改为
...
limit(100,1)
.toList().get(0)

则获得的是正确的offset 100条以后的第一条记录.

请问一下这样的情况是bug, 还是设计的逻辑本就如此?

@xuejmnet
Copy link
Collaborator

@swiftlei 我猜你想要的是singleOrNull

@xuejmnet
Copy link
Collaborator

singlexxx会返回并且断言至多一条

@xuejmnet
Copy link
Collaborator

limit的操作是覆盖之前的limit,firsXXX自带limit(1)

@xuejmnet
Copy link
Collaborator

limit的设计之初是同层级limit多次会覆盖之前的,同层级是指在遇到下一个select之前,因为每次select相当于是一次匿名表比如select * from (select id,name from table where xxx) t

@swiftlei
Copy link
Author

@swiftlei 我猜你想要的是singleOrNull

谢谢,所以如果需要我要的取第101条数据的效果,应该是 limit(100,1).singleOrNull()?

@xuejmnet
Copy link
Collaborator

@swiftlei 是的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants