Skip to content
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

support exclude column #1261

Closed
yuhaya opened this issue Nov 28, 2022 · 2 comments · Fixed by #1264
Closed

support exclude column #1261

yuhaya opened this issue Nov 28, 2022 · 2 comments · Fixed by #1264
Assignees

Comments

@yuhaya
Copy link

yuhaya commented Nov 28, 2022

Motivation

The data table has 20 fields, but I only want to query 19 of them. Sea-orm does not seem to support field exclusion at present. It is too troublesome to call .column() 19 times

Proposed Solutions

add select api

fn column_exclude<C>(mut self, col: C) -> Self
    where
        C: ColumnTrait,
    {
        // code...
        self
    }
@billy1624
Copy link
Member

Hey @yuhaya, welcome!! Thanks for the suggestions! I just created a PR to perform similar operation.

sea-orm/src/query/helper.rs

Lines 115 to 131 in 1520bea

/// Conditionally select all columns expect a specific column
///
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
/// .select_only()
/// .columns(cake::Column::iter().filter(|col| match col {
/// cake::Column::Id => false,
/// _ => true,
/// }))
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"SELECT "cake"."name" FROM "cake""#
/// );
/// ```

@yuhaya
Copy link
Author

yuhaya commented Nov 29, 2022

Hey @yuhaya, welcome!! Thanks for the suggestions! I just created a PR to perform similar operation.

sea-orm/src/query/helper.rs

Lines 115 to 131 in 1520bea

/// Conditionally select all columns expect a specific column
///
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
///
/// assert_eq!(
/// cake::Entity::find()
/// .select_only()
/// .columns(cake::Column::iter().filter(|col| match col {
/// cake::Column::Id => false,
/// _ => true,
/// }))
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"SELECT "cake"."name" FROM "cake""#
/// );
/// ```

good!

@billy1624 billy1624 moved this from Triage to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants