-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
Cursor pagination #822
Cursor pagination #822
Conversation
Is there a PR for upgrading sea-query to 0.25? |
* Custom join condition (SeaQL/sea-orm#793) * Migration does not depend on entity crate * Define integer enum with repr[x] syntax * Document datatype mappings (SeaQL/sea-orm#772) * Cursor pagination (SeaQL/sea-orm#754, SeaQL/sea-orm#822) * (de)serialize custom JSON types (SeaQL/sea-orm#794) * Generate new migration file (SeaQL/sea-orm#656) * Skip generating entity file for specific tables (SeaQL/sea-orm#837) * Generate entity with date time crate option (SeaQL/sea-orm#724) * Drop `SelectTwoMany::one()` method (SeaQL/sea-orm#813) * Datatype mappings of primitives (SeaQL/sea-orm#850, SeaQL/sea-schema#75) * Join with table alias (SeaQL/sea-orm#852) * SQLx logging level (SeaQL/sea-orm#800) * Insert with on conflict (SeaQL/sea-orm#791) * Migrate generate should take file name as argument instead of option (SeaQL/sea-orm#870) * Upgrade docusaurus to 2.0.0-beta.22 * What's new in SeaORM 0.9.0 * Move migration section forward * Rename "Generating Database Schema" section to "Generating SeaQuery Statement" * Fix broken links * Edit * Edit * Edit * Edit Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
Is there any plan to have cursor in other directions? Like if we want to have |
Hey @penso, thanks for asking!! This is exactly what use sea_orm::{entity::*, query::*, tests_cfg::cake};
// Create a cursor that order by `cake`.`id`
let mut cursor = cake::Entity::find().cursor_by(cake::Column::Id);
// Filter paginated result by `cake`.`id` > 1 AND `cake`.`id` < 100
cursor.after(1).before(100);
// Get last 10 rows (order by `cake`.`id` DESC but rows are returned in ascending order)
for cake in cursor.last(10).all(db).await? {
// Do something on cake: cake::Model
} Docs: https://www.sea-ql.org/SeaORM/docs/basic-crud/select/#cursor-pagination |
Wouldn't it be easier to have:
so we don't need to convert/reverse the resulted array if we actually want to deliver the last ID first and in descending order? |
Hey @penso, I think we have add two additional method - // Get first 10 rows (order by `cake`.`id` ASC but rows are returned in descending order)
for cake in cursor.first_desc(10).all(db).await? {
// Do something on cake: cake::Model
}
// Get last 10 rows (order by `cake`.`id` ASC but rows are returned in descending order)
for cake in cursor.last_desc(10).all(db).await? {
// Do something on cake: cake::Model
} |
Is there any drawback to just |
Good question! @penso? |
No drawback than I can think of, except the mental thinking. I've done a "manual" cursor this week-end and will try to move to |
Please! And let us know your experience after using it :) |
Continue #754
Things to do:
I released the
clear_order_by
in sea-query 0.25So the dependency is to upgrade sea-orm to sea-query 0.25.1