-
BackendPostgreSQL Diesel version2.3.7 Diesel Featureschrono postgres Operating System VersionArch Linux Third party librariesNo response What do you want to do?I want to use I use Compile time errorNo response What code do you already have?This is what it looks like (the struct isn't using fields from all the joins, it's just to illustrate).
#[derive(HasQuery)]
#[diesel(base_query = pieces::table.inner_join(piece_status_types::table).left_join(piece_creation_dates::table).left_join(piece_dimensions::table))]
#[diesel(table_name = pieces)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct PieceWithStatus {
pub id: i64,
pub title: String,
#[diesel(select_expression = piece_status_types::title)]
pub status: String,
}
I can manually make it look like this:
```rust
#[derive(HasQuery)]
#[diesel(base_query = pieces::table
.inner_join(piece_status_types::table)
.left_join(piece_creation_dates::table)
.left_join(piece_dimensions::table))]
#[diesel(table_name = pieces)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct PieceWithStatus {
pub id: i64,
pub title: String,
#[diesel(select_expression = piece_status_types::title)]
pub status: String,
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
The likely best solution here is to put your query into a separate function + use This would look like this here: #[diesel::dsl::auto_type]
fn piece_with_status_base_query() -> _ {
pieces::table
.inner_join(piece_status_types::table)
.left_join(piece_creation_dates::table)
.left_join(piece_dimensions::table
}
#[derive(HasQuery)]
#[diesel(base_query = piece_with_status_base_query()))]
#[diesel(table_name = pieces)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct PieceWithStatus {
pub id: i64,
pub title: String,
#[diesel(select_expression = piece_status_types::title)]
pub status: String,
}In that way rustfmt will just format that function as a normal rust function and the attribute is short enough to not cause any issues. Otherwise I believe it would be still good if rustfmt actually tried to format that attribute, although that's an issue that needs to be reported at their issue tracker. It would be great to mention that somewhere in our documentation. Would you be open to submit a PR for that? |
Beta Was this translation helpful? Give feedback.
The likely best solution here is to put your query into a separate function + use
#[diesel::dsl::auto_type]there.This would look like this here:
In that way rust…