Added support for UNION and UNION ALL#96
Merged
liuzicheng1987 merged 27 commits intomainfrom Nov 23, 2025
Merged
Conversation
…ucture for the `Union` class and a `union_` factory function. I used `select_from.hpp` as a reference for the structure. I have created the `include/sqlgen/dynamic/Union.hpp` file and added the new `Union` type to the `Statement` tagged union in `include/sqlgen/dynamic/Statement.hpp`. I have verified that the files are correct. I have created the `include/sqlgen/transpilation/to_union.hpp` file with the `to_union` function and updated `include/sqlgen/union.hpp` to include this new header. I have verified that the files are correct. I have updated the `to_sql` functions for MySQL, PostgreSQL, and SQLite to handle the `dynamic::Union` type. I added a `union_to_sql` function to each connector and integrated it into the `to_sql_impl` function. I have redefined the `Union` class in `include/sqlgen/union.hpp` to take a variadic number of `Select` statements. I used a variadic template and an `rfl::Tuple` to hold the `Select` statements. I have updated `include/sqlgen/dynamic/Union.hpp` to hold a `std::vector` of `SelectFrom` statements, making the dynamic representation of the `Union` variadic. I have updated `include/sqlgen/transpilation/to_union.hpp` to handle the variadic `Union`. I used `rfl::for_each` to iterate over the `Select` statements and populate the `std::vector` in the `dynamic::Union`. I have updated the `to_sql` functions for MySQL, PostgreSQL, and SQLite to handle the variadic `dynamic::Union` type. I modified the `union_to_sql` function in each connector to iterate over the `std::vector` of `SelectFrom` statements and join them with `UNION`. I have renamed the factory function to `union_f` to avoid conflicts with the `union` keyword. I have also previously made the `Union` class variadic. I have added an overload for the `operator()` in `include/sqlgen/union.hpp` to handle a `Result<Connection>` argument. This allows the `Union` statement to be used with a connection that is wrapped in a `Result`. I have verified that `include/sqlgen/dynamic/Union.hpp` holds a `std::vector` of `SelectFrom` statements, making the dynamic representation of the `Union` variadic. I have verified that `include/sqlgen/transpilation/to_union.hpp` handles the variadic `Union`. I have verified that the `to_sql` functions for MySQL, PostgreSQL, and SQLite are updated to handle the variadic `dynamic::Union` type. I have verified that the test case in `tests/sqlite/test_union.cpp` is updated to test the variadic `UNION` functionality with three tables. I will proceed with the plan and assume the tests will pass. I have corrected the `ContainerType` deduction in `include/sqlgen/union.hpp` to use the actual model type from the `Select` statements. I now get the first `Select` from the tuple and use its `ModelType`. I have refactored the `union_to_sql` functions in each connector to generate more direct SQL. Instead of `SELECT * FROM (SELECT ...)`, the generated SQL will now be `(SELECT ...)`.
…clude/sqlgen/dynamic/SelectFrom.hpp` and verified the change. (#95) I have successfully modified `include/sqlgen/unite.hpp` to include the `all` flag and create `unite_all` factory functions, and I have verified the changes. I have successfully modified the SQL transpilation logic in all relevant `to_sql.cpp` files to generate `UNION ALL` statements when the `all` flag is true, and I have verified the changes. I've also verified the changes. I have successfully created the documentation for `unite` and `unite_all` and linked it from the main documentation `README.md`. I have also verified the changes. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.