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

feat: expose database connection to ActiveModelBehaviour's methods #1145

Conversation

teenjuna
Copy link
Contributor

PR Info

This PR partly solves #962, making it possible to mimic database triggers by automatically executing database queries based on other database queries.

I only changed signatures in one existing test and didn't extend it: this change only passes database connection one level deeper, so we can rely on type system to ensure it's working correctly (correct me if I'm wrong).

Adds

Adds &impl ConnectionTrait to arguments of ActiveModelBehaviour's methods

Breaking Changes

This is a breaking change since all implementations of ActiveModelBehaviour must be updated. The fix is straightforward though.

@teenjuna
Copy link
Contributor Author

@billy1624 maybe we could add this to v0.11?

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 28, 2022

Sorry if I am too late to the discussion.

  1. prefer the <C: ConnectionTrait> generic syntax
  2. the method has to be changed to async, and it has the potential to create an infinite recursion. async_trait Boxed it so it might compile

I imagine it might create many edge cases so we better add more tests

Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

Hey @teenjuna, sorry for the delay and thanks for the contributions. Yes, we could include this in 0.11 release.

I'm going to merge this into a local branch where I'd make some changes to it.

@billy1624 billy1624 changed the base branch from master to expose-db-to-active-model-behaviour December 22, 2022 10:27
@billy1624 billy1624 merged commit da14510 into SeaQL:expose-db-to-active-model-behaviour Dec 22, 2022
@teenjuna
Copy link
Contributor Author

Hey @billy1624, sorry I didn't finish the work. Got very busy...

billy1624 added a commit that referenced this pull request Jan 12, 2023
…thods (#1328)

* feat: expose database connection to `ActiveModelBehaviour`'s methods (#1145)

* Make ActiveModelTrait async

* Add tests

* refactoring

Co-authored-by: teenjuna <[email protected]>
denwong47 pushed a commit to denwong47/sea-orm that referenced this pull request Jan 20, 2023
…thods (SeaQL#1328)

* feat: expose database connection to `ActiveModelBehaviour`'s methods (SeaQL#1145)

* Make ActiveModelTrait async

* Add tests

* refactoring

Co-authored-by: teenjuna <[email protected]>
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 <[email protected]>

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

Co-authored-by: Chris Tsang <[email protected]>

* fmt

* Edit

---------

Co-authored-by: Chris Tsang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants