-
Notifications
You must be signed in to change notification settings - Fork 346
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
Easy table definition with C++17/20 #482
Comments
Thanks for documenting your ideas in detail. I like the style you are proposing. TBH, I am still hoping to get reflection and generation in C++ at some point. That would make sqlpp much easier to write, I think. |
Thanks
TBH I would love it as well, it would indeed make things incredibly easier and allow to express one's intention with barely more than a structure definition representing a table. Alas, even with a lot of optimism, we will have to wait quite a long time still before it happens, I think. |
Yeah, reflection and generation will take several years for sure. As you may have seen, there is a version of sqlpp17, which is not too far from being usable, I believe. @Leon0402 is working on that in irregular intervals. I also started sqlpp20 some time ago but gave up back in the day as the support for modules and concepts was very much incomplete back then. That said: I won't invest a lot of time into a C++17/20 version myself, but I would applaud efforts in this direction :-) |
Very irregular intervals :/ As always so much other stuff to do. But I would love to find more time for sqlpp17. The only advantage is that by the time I brought sqlpp17 in shape, support for modules and that stuff will be available and we can port it to C++20 ;) |
I will start contributing to sqlpp17. @Leon0402: I have many other things to do and my needs of SQL are not quite of the most complex order, so my contributions might be limited to the sort I proposed earlier. As I noted, for what I propose to work under C++17, I think it should only need deduction guides for the |
@FunMiles Actually another nice improvement in C++20 is that it supports |
I know this is sqlpp11. However one can use it within a C++17/20 context and exploits some of the features of these languages to further simplify the usage of sqlpp11.
@rbock does not like macros more than I do and the use of a separate preprocessor is not always adequate.
I have noted in the wishlist the desire for support for
CREATE
as well as the ideas of converting between SQL and C++ structs.I decided to create table descriptions by hand, using a few helpers.
First, one can make use of fixed_string:
With the current implementation, one needs to be able to still obtain a character sequence from a fixed_string:
To make a DRY version of column and table, a little utility that is used to define
_alias_t
. Here I am using structured binding to be able to obtain the data from a passed parent class template containing a single member:And finally one can define column-declaration and table-declaration types:
With these in place, providing columns and table definitions becomes simple with little boiler plate. First create templated structures that give a name to variables and use those to define both columns and tables:
Now if only I could write:
AlphaDeltaTable table{}; db( create( table ).if_not_exist() );
Could this make it into sqlpp17/20? Nothing seems to have changed in a long while there and sqlpp11 is still touted as the stable version to use. Could make such tool make it into a
future
directory for users of more recent C++ version? (C++17 is now default on most compilers and thefixed_string
only needs two more lines or so to work under C++17)The text was updated successfully, but these errors were encountered: