Add select_except
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 734
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
https://github.com/SeaQL/sea-orm/discussions/3026#discussioncomment-16994303
I’d probably avoid
#[lazy]on the normalModel.If
fileis part of the model type but not actually loaded, then every access needs some hidden state like “loaded / not loaded / loading failed”. That makes the model less predictable and easy to misuse.For this case I’d keep it explicit:
#[derive(Debug, FromQueryResult)] struct EntryWithoutFile { id: i32, name: String, }let rows = Entity::find() .select_only() .column(Column::Id) .column(Column::Name) .into_model::<EntryWithoutFile>() .all(db) .await?;Then load the blob only when needed:
let file: Option<Vec<u8>> = Entity::find_by_id(id) .select_only() .column(Column::File) .into_tuple() .one(db) .await?;So imo a
defer()/select_except()style API would fit SeaORM better than lazy fields onModel.Something like this would be really nice:
Entity::find() .select_except([Column::File]) .all(db) .await?;For bigger files, I’d also consider moving the bytes to object storage / filesystem and keeping only metadata + path/key in DB. But if the files are small and DB storage is intentional, explicit projection + a helper method is probably the cleanest workaround for now.
Maybe you can wrap it like:
impl EntryWithoutFile { async fn load_file(&self, db: &DatabaseConnection) -> Result<Option<Vec<u8>>, DbErr> { Entity::find_by_id(self.id) .select_only() .column(Column::File) .into_tuple() .one(db) .await } }Not as magic as
#[lazy], but much clearer and avoids accidentally fetching blobs in list queries.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the existing Entity::find().select_only() query-selection API and trace how selected columns are represented and applied. Add a select_except([Column::File])-style entry point whose completed behavior excludes the requested column while preserving the remaining query results; verify it with the project’s existing query-selection tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100