How can I implement default for something generated by the client? #100
-
My code is as follows: pub async fn get_user_data(user_id: i64) -> user_data::Data {
let client = CONNECTION.get().unwrap();
let data = client.user_data().find_first(vec![user_data::discord_id::equals(user_id)]).exec().await.unwrap();
data.unwrap_or_default()
} However, this Data struct (generated by Prisma) doesn't implement Default, and I don't want to manually write an implementation manually. Any ideas on how I could do this? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
More or less you can't. I purposefully don't implement Default since that's out of scope of Prisma Client Rust, plus even if it did I'd argue that in your case it isn't helpful, since the ID of the user data wouldn't be equal to |
Beta Was this translation helpful? Give feedback.
More or less you can't. I purposefully don't implement Default since that's out of scope of Prisma Client Rust, plus even if it did I'd argue that in your case it isn't helpful, since the ID of the user data wouldn't be equal to
user_id
(unless you reassign it).You can implement Default manually yourself if you really want to, but I think a better solution is to create a custom struct that you can convert
user_data::Data
to, and then derive Default on it.You can also create an instance of
user_data::Data
and specify all the parameters yourself but I imagine that's not a great experience.