-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Update ActiveModelBehavior
API
#210
Conversation
27ed1c6
to
ef1eb57
Compare
Great job @billy1624, there is a few things that would be cool to have in this PR. 1st) is to rollback db changes on failure. pub trait ActiveModelBehavior: ActiveModelTrait {
Type Error: std::error::Error;
fn after_save(self, insert: bool, db: &DatabaseConnection) -> Result<Self, Self::Error> {
Ok(self)
}
// .. omitted
} |
This requires Transaction support and it's not merged into master yet.
Perhaps we can introduce #[derive(Debug)]
pub enum DbErr {
Conn(String),
Exec(String),
Query(String),
Custom(Box<dyn Error>),
} |
Using |
we can also have an alias for such a result type like this: // we can also name this BehaviorResult<T> or other good name, so we can add it in the prelude
type Result<T> = Result<T, Box<dyn Error>>;
pub trait ActiveModelBehavior: ActiveModelTrait {
fn before_save(self, insert: bool, db: &DatabaseConnection) -> Result<Self> { .. }
// .. omited
} |
Or another option is to |
But this conversion will have a long lasting impact. Converting all errors defined in third-party crate into I think it's okay as long as we don't change this conversion afterward. Otherwise, this will be a headache for downstream users. |
I think it is better to not provide a blanket implementation for now. It looks good otherwise. |
a5c8290
to
01fecbc
Compare
Hey @MuhannadAlrusayni, I will not include
|
Hey @tyt2y3, this is ready to merge. Will add unit tests for this PR together with transaction once it's merged |
* Support 'NULLS LAST' and 'NULLS FIRST' * By defualt, don't write 'order by nulls' in QueryBuilder * Add `Nulls` enum instead of boolean for represent nulls order * `OrderedStatement`: rename `order_by_xxx_nulls_last` to `order_by_xxx_with_nulls` * `OrderedStatement`: place nulls into cols tuple in `order_by_xxxs_with_nulls` * Add `nulls order` support for Mysql backend * fix: `NULLS FIRST` typo * test: order by with nulls on all backends * Rename enum `Nulls` to `NullOrdering` Co-authored-by: Billy Chan <[email protected]> Co-authored-by: Chris Tsang <[email protected]>
Resolve #161