Replies: 3 comments
-
|
Could be a feature. Side note: if you have control over the schema, storing files on disk/object storage and keeping only a path/URL in the DB is recommended. |
Beta Was this translation helpful? Give feedback.
-
|
I feel like although |
Beta Was this translation helpful? Give feedback.
-
|
I’d probably avoid If 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 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 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm storing files in my database which are quite small, but when i query 50+ entries, it starts to pile up. Would there be a way in SeaORM to have a lazy loaded Vec or a way to mark fields as "lazy" which would generate getter methods ?
For now, I am using custom models, selecting all columns but
file, but it makes this more cumbersomeBeta Was this translation helpful? Give feedback.
All reactions