Skip to content

#[derive(Serialize)] for Record #1073

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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sqlx-macros/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ where
);

let mut record_tokens = quote! {
#[derive(Debug)]
#[derive(Debug,Serialize)]
// I cannot get this to work:
// #[cfg_attr(feature = "json", derive(Serialize))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json feature needs to be tested outside of quote! so it can look for the feature in the sqlx-macros crate and not whatever crate invoked the derive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, you'll want to do serde::Serialize so the user doesn't need to have the derive imported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should re-export serde in a #[doc(hidden)] exports module and use it as ::sqlx::export::serde::Deserialize so the user doesn't need to depend on serde directly either.

struct #record_name {
#(#record_fields)*
}
Expand Down