-
-
Notifications
You must be signed in to change notification settings - Fork 339
SQL Query Views #1481
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
Open
trueqbit
wants to merge
58
commits into
dev
Choose a base branch
from
experimental/sql-view
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
SQL Query Views #1481
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
ee3abe3
Started implementing SQL views
trueqbit ea10616
Merged upstream/dev into experimental/sql-view
trueqbit 89b4805
Renamed `storage_t<>::sync_table()` -> `storage_t<>::sync_dbo()`
trueqbit 8fc8506
Used `c_str()` instead of `data()` for executing SQL string
trueqbit 3627014
Added SQL view to the schema
trueqbit 759aa24
Guarded availability of the SQL view feature
trueqbit 5f9b0c7
Alias template that filters columns of a table
trueqbit 8b3902a
Made sql views working with CTEs
trueqbit 733e1b7
Used the new facility to access the main select to reduce lines of code
trueqbit add9aeb
Generalized preparing and executing 'raw' DML statements
trueqbit 5b23b3c
Streamlined executing and logging SQL statements
trueqbit 996c34e
Generalized serializer context
trueqbit aebf0cf
Restructured classes representing table database objects
trueqbit 1c363c1
Pull in Boost PFR if available
trueqbit d450e3d
Merge branch 'upstream/feature/rtree-vtab' into experimental/sql-view
trueqbit af22d4a
Include SQLite3 configuration in funcational/config.h
trueqbit 5ee55eb
Automatically include boost-pfr if available
trueqbit e3c08e1
Merge branch 'upstream/dev' into experimental/sql-view
trueqbit 0fcfe6a
Direct database operations for
trueqbit 1579107
Renamed `view_t` -> `query_view`
trueqbit 63dbea9
Disable boost-pfr when testing the sqlite_orm C++ module
trueqbit f7cf5d6
Used a custom implementation of `offsetof`
trueqbit a0bdb6c
Merge branch 'dev' into experimental/sql-view
trueqbit 302119f
Merge branch 'dev' into experimental/sql-view
trueqbit 415b462
Removed duplicate C++ feature test
trueqbit c880626
Used `std::size_t` for PFR related function
trueqbit 139bda0
Creation of `query_view` with C++26 reflection syntax
trueqbit b81e4d1
Merge remote-tracking branch 'origin/dev' into experimental/sql-view
trueqbit bbfec0b
`stream_identifier()` with an index sequence needs to be available
trueqbit b3373e4
Used the single-argument version of `static_assert`
trueqbit 273bab0
Accommodated for Clang on Windows, which cannot use constexpr DLL exp…
trueqbit af5a8c3
Merge branch 'clang-related' into experimental/sql-view
trueqbit d62d21f
Merge branch 'dev' into experimental/sql-view
trueqbit 8de3fac
Added an example for SQL views
trueqbit c0890d9
Merge branch 'c++17-code-quality' into experimental/sql-view
trueqbit ea1dcee
Merge branch 'dev' into experimental/sql-view
trueqbit e8d30b0
Compile with `gcc-16 -std=c++26 -freflection`
trueqbit 1bfd411
Merge remote-tracking branch 'origin/dev' into experimental/sql-view
trueqbit 98709d0
`rank()` should only be used as a window function
trueqbit 2b9a462
Sync query views with schema
trueqbit 98bdf43
Corrected compile options target for examples
trueqbit 30cbcab
Updated .clang-format-ignore with paths that the github linter action…
trueqbit 663fa8b
Corrected superfluous space before comments
trueqbit f84a9d9
Updated TODO.md
trueqbit 87b8913
Removed fallback to Boost.PFR for query views
trueqbit 7ce965a
Removed code used in local test environment
trueqbit 2c1121f
Address a few things popping up when compiling with GCC
trueqbit f80f0de
Supply query view name via C++ annotation
trueqbit 4027035
Adjust testing enabled query view
trueqbit 5c7e8ec
Corrected no-warning option
trueqbit 5398c1d
Corrected a few mixed up things again
trueqbit 68382d8
Capture only the variables that are needed
trueqbit fcbfb11
Considered base members for reflected views/tables
trueqbit c3b847b
github actions: try C++26/gcc-16 tests
trueqbit 1ced217
Addressed points raised in review
trueqbit 234e5f9
Use github action lukka/run-vcpkg with only the major version 11 again
trueqbit d8d39ed
Renamed `dbo_name_t` -> `dbo_name_literal`
trueqbit eb8f233
Merge remote-tracking branch 'origin/dev' into experimental/sql-view
trueqbit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # exclude until clang-format understands C++ reflection syntax | ||
| ./dev/functional/meta_util.h |
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #pragma once | ||
|
|
||
| #ifndef SQLITE_ORM_IMPORT_STD_MODULE | ||
| #ifdef SQLITE_ORM_REFLECTION_SUPPORTED | ||
| #include <array> // std::array | ||
| #include <meta> // std::define_static_array, std::meta::access_context, std::meta::nonstatic_data_members_of, std::meta::identifier_of, std::meta::annotations_of | ||
| #include <tuple> // std::tuple | ||
| #include <utility> // std::index_sequence, std::make_index_sequence | ||
| #endif | ||
| #endif | ||
|
|
||
| #ifdef SQLITE_ORM_REFLECTION_SUPPORTED | ||
| namespace sqlite_orm::internal { | ||
| /** | ||
| * Reflects the non-static data members of `T` and its base classes | ||
| * and returns them as a fixed-size span of `std::meta::info` reflections. | ||
| */ | ||
| template<class T> | ||
| consteval auto extract_members() { | ||
| constexpr auto ctx = std::meta::access_context::current(); | ||
|
|
||
| constexpr auto collect = []<class U>(this const auto& self) -> std::vector<std::meta::info> { | ||
| std::vector<std::meta::info> result; | ||
|
|
||
| // Recurse into direct base classes first (preserves layout order) | ||
| template for (constexpr std::meta::info base : std::define_static_array(bases_of(^^U, ctx))) { | ||
| using base_type = typename[:type_of(base):]; | ||
| result.append_range(self.template operator()<base_type>()); | ||
| } | ||
|
|
||
| // Then this class's own non-static data members | ||
| result.append_range(nonstatic_data_members_of(^^U, ctx)); | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| return std::define_static_array(collect.template operator()<T>()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the identifier of `T`. | ||
| */ | ||
| template<class T> | ||
| consteval auto extract_type_identifier() { | ||
| return std::meta::identifier_of(^^T); | ||
| } | ||
|
|
||
| /** | ||
| * Splices a non-static data member reflection into a member-pointer expression. | ||
| * Encapsulated here so the splice operator does not leak into consumer headers. | ||
| */ | ||
| template<std::meta::info member> | ||
| consteval auto splice_member_pointer() { | ||
| return &[:member:]; | ||
| } | ||
|
|
||
| /** | ||
| * Splices a reflection's annotations into a tuple of values. The reflection may be | ||
| * a type or a non-static data member. | ||
| * Encapsulated here so the splice operator does not leak into consumer headers. | ||
| * | ||
| * Two P3394 details inform this implementation: | ||
| * - Annotation reflections returned by `annotations_of` are not directly spliceable; | ||
| * they must first be routed through `std::meta::constant_of`, which returns a | ||
| * splice-able constant reflection. | ||
| * - `std::meta::annotations_of` returns a `std::vector<std::meta::info>`, whose heap | ||
| * allocation is transient under C++20 constexpr rules and cannot be bound to a | ||
| * `constexpr` variable. The size and per-index lookups therefore re-call | ||
| * `annotations_of` inline so each transient vector dies within its own constant | ||
| * expression. | ||
| */ | ||
| template<std::meta::info refl> | ||
| consteval auto splice_annotations() { | ||
| return []<size_t... I>(std::index_sequence<I...>) consteval { | ||
| return std::tuple{[:std::meta::constant_of(std::meta::annotations_of(refl)[I]):]...}; | ||
| }(std::make_index_sequence<std::meta::annotations_of(refl).size()>{}); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the class-scope annotations of `T` as a tuple. | ||
| */ | ||
| template<class T> | ||
| consteval auto extract_type_annotations() { | ||
| return splice_annotations<^^T>(); | ||
| } | ||
| } | ||
| #endif |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #pragma once | ||
|
|
||
| #ifndef SQLITE_ORM_IMPORT_STD_MODULE | ||
| #ifdef SQLITE_ORM_REFLECTION_SUPPORTED | ||
| #include <string_view> // std::string_view | ||
| #include <tuple> // std::tuple | ||
| #include <type_traits> // std::bool_constant | ||
| #include <utility> // std::forward | ||
| #endif | ||
| #endif | ||
|
|
||
| #include "../functional/cstring_literal.h" | ||
| #include "../functional/meta_util.h" | ||
| #include "../functional/mpl.h" | ||
| #include "../tuple_helper/tuple_filter.h" | ||
| #include "../tuple_helper/tuple_traits.h" | ||
|
|
||
| #ifdef SQLITE_ORM_REFLECTION_SUPPORTED | ||
| namespace sqlite_orm::internal { | ||
| /** | ||
| * Class-scope annotation that overrides the database object name (table or view). | ||
| * When absent, the name falls back to `std::meta::identifier_of(^^T)`. | ||
| * | ||
| * The string is embedded in the type's bytes via `cstring_literal<N>` rather than | ||
| * carried by pointer + size: pointers to string literals are not accepted as | ||
| * annotation values by current reflection implementations (the underlying object | ||
| * has no linkage), so a self-contained fixed-size byte array is required. | ||
| */ | ||
| template<size_t N> | ||
| struct dbo_name_literal : cstring_literal<N> { | ||
| constexpr dbo_name_literal(const char (&cstr)[N]) : cstring_literal<N>{cstr} {} | ||
|
|
||
| constexpr auto name() const noexcept { | ||
| return this->cstr; | ||
| } | ||
| }; | ||
|
|
||
| template<class T> | ||
| constexpr bool is_dbo_name_v = false; | ||
|
|
||
| template<size_t N> | ||
| constexpr bool is_dbo_name_v<dbo_name_literal<N>> = true; | ||
|
|
||
| template<class T> | ||
| using is_dbo_name = std::bool_constant<is_dbo_name_v<T>>; | ||
|
|
||
| /** | ||
| * Returns the database object name carried by the `dbo_name_literal<…>` element of `annotations`, | ||
| * or the type's reflected identifier when no such element is present. | ||
| */ | ||
| template<class T, class Tuple> | ||
| constexpr std::string_view resolve_dbo_name(const Tuple& annotations) { | ||
| using name_index = find_tuple_element<Tuple, is_dbo_name>; | ||
|
|
||
| if constexpr (name_index::value < std::tuple_size_v<Tuple>) { | ||
| return std::get<name_index::value>(annotations).name(); | ||
| } else { | ||
| return extract_type_identifier<T>(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns a copy of `tuple` with all `dbo_name_literal<…>` elements removed. | ||
| */ | ||
| template<class Tuple> | ||
| constexpr auto filter_out_dbo_name(Tuple&& tuple) { | ||
| using constraints_index_sequence = filter_tuple_sequence_t<Tuple, check_if_not<is_dbo_name>::template fn>; | ||
| return create_from_tuple<std::tuple>(std::forward<Tuple>(tuple), constraints_index_sequence{}); | ||
| } | ||
| } | ||
|
|
||
| SQLITE_ORM_EXPORT namespace sqlite_orm { | ||
| /** | ||
| * Database object name annotation factory. | ||
| * Use as a class-scope annotation: `struct [[=dbo_name("users")]] User { ... };`. | ||
| * Both `make_table<T>()` and `make_view<T>()` consume this annotation; when absent | ||
| * the name falls back to `T`'s reflected identifier. | ||
| */ | ||
| template<size_t N> | ||
| constexpr internal::dbo_name_literal<N> dbo_name(const char (&dboName)[N]) { | ||
| return {dboName}; | ||
| } | ||
| } | ||
| #endif |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to deprecate it cause it is also used in window funcs and it is not going to be deprecated there. So I'd remove
[Deprecation notice]Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order_by(rank())can only be used with FTS not with Window functions, that's why I added it here (actually moved from therank()factory).