-
Notifications
You must be signed in to change notification settings - Fork 344
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
Future improvements of sqlpp11 #500
Comments
Thanks for the thoughtful migration / implementation!
👍
Thanks for looking into those.
That is a good observation. it certainly makes sense to unify and make use of that in the connection pool.
Not a priority in my view, but probably makes sense, yes.
SGTM
Yes, I am in favor of that. There used to be some problems with older compiler versions (or my faulty understanding of the standard), but it is definitely worth trying to use more uniform initialization.
That I am not a fan of. In my view, this creates a lot of unnecessary noise in the code, especially for templates.
I have been debating with myself whether to create a simple c++11 version of
I am not going to invest a lot of effort in sqlpp17 or sqlpp20 for now. As said elsewhere, I am looking forward to a time when reflection and generation are a thing in C++ :-) Thanks for sharing your ideas! Looking forward to more detailed discussions and/or pull requests. Cheers, |
Using a custom, simplified version of std::optional makes sense. Actually, if keeping C++11 compatibility is required, then a custom std::optional is probably the only sane approach.
I am not sure how you plan to use the support of C++ reflection in sqlpp, but maybe you have seen taopq. They are somewhat similar to sqlpp in the sense that they are not an ORM but more of a database abstraction layer with type checking. They do support aggregate data types (e.g. structures) as query input parameters and results. A while ago I looked into their implementation and it is done using structured binding (which obviously requires C++17). E.g. it seems to me that here they decompose the aggregate data and prepare it for sending to the database (e.g. as a query parameter): https://github.com/taocpp/taopq/blob/main/include/tao/pq/internal/aggregate.hpp That approach cannot be used directly in sqlpp11 as it requires C++17, but it might serve as food for thought. |
@rbock One thing that I noticed is that for PostgreSQL the connection_handle class is moved into a separate file (
|
Looking forward to it, thanks!
Right. The different connector authors are clearly visible in some places. Streamlining these is certainly helping with readability.
Yes, that makes sense, I think.
Yes. I am leaning to
Maybe. If it can be done nicely, then yes. connection and context are quite closely coupled. I might be easier for them to stay in one file.
There is a lack of consistency, indeed. Today, I'd say the |
@rbock So for now I am planning the following PRs:
|
@MeanSquaredError I hope you don't mind me chiming in here. |
Actually I will split the first PR
into three separate PRs, one for MySQL, one for PostgreSQL and one for SQLite3. Having them all in one PR would make it too big and difficult to review |
@CJCombrink
and thus all constructors for the connector classes are defined in |
@rbock
That might cause name collisions with variable names or C++ keywords (e.g. Also we have
Could that lead to name collisions too? Maybe it still makes sense to have some special prefix/suffix for these special structures that are used to build the SQL expressions? E.g. the prefix |
True. Removing Re-reading what I wrote in the previous comment, I should clarify: I meant that if I wrote the library again, today, I would remove the But doing so in the existing library might not be worth it. |
@rbock If that is OK with you, then I will go ahead and rename the classes/structs. What do you think? |
@rbock Thank you for merging the connection pools into the main branch.
I made a list of things that may be improved in future versions of sqlpp.
BUGS:
One of the MySQL tests (sqlpp11.mysql.usage.DateTime) fails on my development machine. This is not related to the new connection pools code, because it failed before too. I am not sure of the exact reason, one (unlikely) reason could be because I am using the MySQL connector to connect to a MariaDB. I will try investigating and fixing it.The MariaDB and SQLCipher connectors fail to build on my machine. I took a quick look and it seems that the cmake for these two has problems. I will investigate that in more detail.IMPROVEMENTS OF THE CURRENT FUNCTIONALITY
Currently the connectors have different non-standard ways to check if the connection/handle is connected to the server. MySQL has a connection::is_valid() which essentially calls mysql_ping(). PostgreSQL just calls PQstatus() which checks passively if the remote server has closed the connection or if a previous request had an error. SQLite has nothing :-)Currently when the connection pool checks the handle status it just uses whatever functionality the connector supports which varies depending of the connector.
So it really makes sense to standardize this. Each connection and connection_handle should have two methods:
1. is_connected() checks if the connection has been established and the remote side has not closed the connection.2. ping_server() actively pings the server. For PostgreSQL and SQLite3 we can just use the approach of PHP's pg_ping() that sendsSELECT 1
to the server and checks if there is an error.Once we have standardized the is_connected() and ping_server() for connections, we can enhance slightly connection_pool::get() and make it accept a parameter which defines the type of the connection check ,e.g:Then based on the requested check type it will perform the corresponding check before giving out the handle. Currently the MySQL connection pool performs a server ping before giving out a handle, which may be unnecessary if the MySQL server is reliable enough. So it makes sense to allow the user to choose the check type.CODE CLEANUPS
These are a matter of taste, but it still probably makes sense to discuss and implement some/all of them.
The headers use old-style #ifdef inclusion guards. I think it makes sense to switch to #pragma once. It is non-standard but everyone supports it and besides sqlpp17 is already using it probably because the #ifdef guards are a headache :-)Using brace-style (uniform) initialization in most places except where C++11 has problems, e.g.auto var = {value}
. The C++ core guidelines by Bjarne Stroustrup recommend switching to brace initialization wherever possible, so it probably makes sense to try using it.Moving the method definitions outside of class body. Arguably the class body should just be a description of the class interface and only have method declarations and all method definition should be made outside of the class. This would make the classes much simpler to read. That rule is not always possible to follow strictly, because in some cases we want to use auto as return type and let the compiler figure out the return type, so in these cases the method definition can be inside the class, but in many other cases they can be moved outside of the class. This will probably help mostly the connectors and connection handle classes.FEATURES THAT REQUIRE C++17 or C++20
I am not sure what is the best way to handle these. Maybe just rename sqlpp11 to sqlpp20 and then implement these features there :-)
The text was updated successfully, but these errors were encountered: