Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Comments

[pin_packing] Paginate query responses#146

Merged
garryod merged 25 commits intomainfrom
pagination
Nov 13, 2023
Merged

[pin_packing] Paginate query responses#146
garryod merged 25 commits intomainfrom
pagination

Conversation

@garryod
Copy link
Contributor

@garryod garryod commented Oct 9, 2023

No description provided.

@garryod garryod added enhancement New feature or request rust Pull requests that update Rust code labels Oct 9, 2023
@garryod garryod self-assigned this Oct 9, 2023
@garryod garryod mentioned this pull request Oct 12, 2023
@garryod garryod force-pushed the pagination branch 4 times, most recently from 02f1fae to 17ae9f8 Compare October 25, 2023 17:01
@garryod garryod requested a review from ndevenish October 26, 2023 10:33
@garryod garryod force-pushed the pagination branch 3 times, most recently from 97c8afb to 88cca9e Compare October 31, 2023 17:00
@ndevenish
Copy link
Collaborator

Let me know when you're done rewriting

Comment on lines +121 to +170
fn try_extract_primary_key<Model>(
model: &Model,
) -> Result<
<<Model::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType,
PrimaryKeyExtractionError,
>
where
Model: ModelTrait,
{
let columns = <Model::Entity as EntityTrait>::PrimaryKey::iter()
.map(|key| key.into_column())
.collect::<Vec<_>>();
let values = match columns.len() {
1 => Ok(ValueTuple::One(model.get(columns[0]))),
2 => Ok(ValueTuple::Two(
model.get(columns[0]),
model.get(columns[1]),
)),
3 => Ok(ValueTuple::Three(
model.get(columns[0]),
model.get(columns[1]),
model.get(columns[2]),
)),
4 => Ok(ValueTuple::Four(
model.get(columns[0]),
model.get(columns[1]),
model.get(columns[2]),
model.get(columns[3]),
)),
5 => Ok(ValueTuple::Five(
model.get(columns[0]),
model.get(columns[1]),
model.get(columns[2]),
model.get(columns[3]),
model.get(columns[4]),
)),
6 => Ok(ValueTuple::Six(
model.get(columns[0]),
model.get(columns[1]),
model.get(columns[2]),
model.get(columns[3]),
model.get(columns[4]),
model.get(columns[5]),
)),
_ => Err(PrimaryKeyExtractionError),
}?;
Ok(<<Model::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::from_value_tuple(
values,
))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to come up with a better alternative to this, but haven't been able to figure one out... The typical approach is a trait with (templated) implementations for each tuple width, but as far as I know there is no way to select on this when looking at an associated type. Any ideas?

@garryod garryod marked this pull request as ready for review November 1, 2023 11:02
@garryod
Copy link
Contributor Author

garryod commented Nov 1, 2023

Let me know when you're done rewriting

Done now

@garryod garryod merged commit 862cf2c into main Nov 13, 2023
@garryod garryod deleted the pagination branch November 15, 2023 18:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants