-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extend sql generation via to_sql attribute
This commit introduces a new `#[to_sql]` attribute that allows for customizing the behavior of SQL generation on certain entities in two different ways: 1. `#[to_sql(false)]` disables generation of the decorated item's SQL 2. `#[to_sql(path::to::function)]` delegates responsibility for generating SQL to the named function In the latter case, the function has almost the same signature as the `to_sql` function of the built-in `ToSql` trait, except the function receives a reference to a `SqlGraphEntity` in place of `&self`. This allows for extending any of the `SqlGraphEntity` variants using a single function, as trying to use specific typed functions for each entity type was deemed overly complex. This also works well with the way `ToSql` is invoked today, which starts by calling the implementation on a value of type `SqlGraphEntity`, so we can perform all the checks in a single place. As an aside, these custom callbacks can still delegate to the built-in `ToSql` trait if desired. For example, if you wish to write the generated SQL for specific entities to a different file. The motivation for this is that in some edge cases, it is desirable to elide or modify the SQL being generated. In our case specifically, we need to chop up the generated SQL so that we can split out non-idempotent operations separately from idempotent operations in order to properly manage extension upgrades. Rather than lose the facilities pgx provides, the `#[to_sql]` attribute allows us to make ad-hoc adjustments to what, when and where things get generated without needing any upstream support for those details.
- Loading branch information
Showing
19 changed files
with
475 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.