Skip to content
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

Unchanged ActiveValue as Set #1177

Merged
merged 4 commits into from
Jan 12, 2023
Merged

Unchanged ActiveValue as Set #1177

merged 4 commits into from
Jan 12, 2023

Conversation

billy1624
Copy link
Member

PR Info

New Features

  • Converting Unchanged active value as Set

@billy1624 billy1624 self-assigned this Nov 1, 2022
@billy1624 billy1624 marked this pull request as ready for review November 1, 2022 08:13
@billy1624 billy1624 requested a review from tyt2y3 November 1, 2022 08:13
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 23, 2022

Umm I think there might be more self-explanatory method names

@billy1624
Copy link
Member Author

Agree! Let me brainstorm it tonight in dream.
Any other naming suggestions are welcomed!

@billy1624
Copy link
Member Author

How about unchanged_value_into_set?

@billy1624
Copy link
Member Author

Okay, renamed

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 24, 2022

I think we should instead only add two methods to ActiveModel: iter and iter_mut.
And then the user can do:

active_model.iter_mut(|(_col, &mut val)| {
    *val = match val {
        ActiveValue::Unchanged(v) => ActiveValue::Set(v),
        _ => (),
    };
});

@billy1624
Copy link
Member Author

Let user perform the conversion on their own?

@billy1624
Copy link
Member Author

We just provide a API to effortlessly iterate all fields in the ActiveModel.

And we should include a code snippet in the cookbook on how to update all Unchanged fields into Set

@billy1624 billy1624 marked this pull request as draft November 24, 2022 08:00
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 24, 2022

May we could have a rechange method on ActiveValue:

active_model.iter_mut(|(_col, &mut val)| {
    *val = val.rechange();
});

Still a bad name though

@billy1624
Copy link
Member Author

I don't think we can have

active_model.iter_mut(|(_col, &mut val: ActiveValue<V>)| {
    *val = match val {
        ActiveValue::Unchanged(v) => ActiveValue::Set(v),
        _ => (),
    };
});

Because it's impossible to have &mut val: ActiveValue<V> where V: Into<Value>.

We can have &mut val: ActiveValue<i32> but then we can't iterate over the columns.

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 28, 2022

Ah I see what you mean, sad :(

@billy1624
Copy link
Member Author

billy1624 commented Nov 28, 2022

Back to the naming problem. How about set_dirty?

Nice editing @tyt2y3

@billy1624 billy1624 marked this pull request as ready for review November 28, 2022 08:58
@billy1624
Copy link
Member Author

Any opinion on the naming? @tyt2y3

@tyt2y3
Copy link
Member

tyt2y3 commented Jan 11, 2023

Back to square 1, can we have reset and reset_all?

@billy1624 billy1624 force-pushed the active-value-as-set branch from a7ec835 to bfe3f18 Compare January 11, 2023 11:57
@billy1624
Copy link
Member Author

Renamed :D

@tyt2y3 tyt2y3 merged commit cb71e26 into master Jan 12, 2023
@tyt2y3 tyt2y3 deleted the active-value-as-set branch January 12, 2023 07:42
denwong47 pushed a commit to denwong47/sea-orm that referenced this pull request Jan 20, 2023
* Unchanged ActiveValue as Set

* Renaming

* Rename

* Rename methods
@billy1624 billy1624 added this to the 0.11.x milestone Jan 31, 2023
billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Feb 3, 2023
tyt2y3 added a commit to SeaQL/seaql.github.io that referenced this pull request Feb 3, 2023
* Update 02-writing-migration.md

* Update SeaORM/docs/03-migration/02-writing-migration.md

* Support various UUID formats that are available in `uuid::fmt` module (SeaQL/sea-orm#1325)

* Casting columns as a different data type on select, insert and update (SeaQL/sea-orm#1304)

* Methods of `ActiveModelBehavior` receive db connection as a parameter (SeaQL/sea-orm#1145, SeaQL/sea-orm#1328)

* Added `execute_unprepared` method to `DatabaseConnection` and `DatabaseTransaction` (SeaQL/sea-orm#1327)

* Added `Select::into_tuple` to select rows as tuples (instead of defining a custom Model) (SeaQL/sea-orm#1311)

* Generate `#[serde(skip)]` for hidden columns (SeaQL/sea-orm#1171, SeaQL/sea-orm#1320)

* Generate entity with extra derives and attributes for model struct (SeaQL/sea-orm#1124, SeaQL/sea-orm#1321)

* Generate entity with extra derives and attributes for model struct (SeaQL/sea-orm#1124, SeaQL/sea-orm#1321)

* async_trait

* Migrations are now performed inside a transaction for Postgres (SeaQL/sea-orm#1379)

* `MockDatabase::append_exec_results()`, `MockDatabase::append_query_results()`, `MockDatabase::append_exec_errors()` and `MockDatabase::append_query_errors()` take any types implemented `IntoIterator` trait (SeaQL/sea-orm#1367)

* Cleanup the use of `vec!` macros

* Added `DatabaseConnection::close` (SeaQL/sea-orm#1236)

* Added `ActiveValue::reset` to convert `Unchanged` into `Set` (SeaQL/sea-orm#1177)

* Added `QueryTrait::apply_if` to optionally apply a filter (SeaQL/sea-orm#1415)

* Added the `sea-orm-internal` feature flag to expose some SQLx types (SeaQL/sea-orm#1297, SeaQL/sea-orm#1434)

* Add `QuerySelect::columns` method - select multiple columns (SeaQL/sea-orm#1264)

* Edit

* Update SeaORM/docs/02-install-and-config/02-connection.md

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>

* Update SeaORM/docs/05-basic-crud/03-insert.md

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>

* fmt

* Edit

---------

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants