Replies: 4 comments 4 replies
-
I think this is a good idea that utilizing Rust type checker to enforce nullability on compile time. However, how can we derive the Can we somehow read nullability of each column from the impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Name => ColumnType::String(None).def().null(),
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I think the central idea here is to use different models for different APIs. |
Beta Was this translation helpful? Give feedback.
-
While building my app, i encountered an error during insert, which could have been prevented by this at compile time. No I want to share my thoughts about this issue:
May possibly insert a default value for types which implement it, which may not be intentional. So i was thinking of the possibility of implementing the ActiveModelStruct as a builder using (const) generics. Using this one is able to track all fields set and unset. The derive macro can then implement an I hope this was helpful. I am very interested in your opinions and insights. |
Beta Was this translation helpful? Give feedback.
-
It doesn't look like SeaORM currently stores information about whether an SQL column has a default value.
Storing this could be useful for generating a new struct perhaps called
InputModel
which wraps each column in anOption<T>
except those that are required (non-nullable) and do not have a default value. Auto-generated primary keys could also be omitted from this struct entirely.This would integrate the Rust type checker with your insert query ensuring it will be valid at compile time.
Eg:
The main use-case for this is integrating with async-graphql.
Beta Was this translation helpful? Give feedback.
All reactions