This repository was archived by the owner on Jul 23, 2024. It is now read-only.
Conversation
Merged
02f1fae to
17ae9f8
Compare
97c8afb to
88cca9e
Compare
Collaborator
|
Let me know when you're done rewriting |
garryod
commented
Nov 1, 2023
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, | ||
| )) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
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?
Contributor
Author
Done now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.