On Wed, 11 May 2022 at 06:16, Dennis Luehring via Boost
Am 10.05.2022 um 22:33 schrieb Marcelo Zimbres Silva via Boost:
users could do
boost::mysql::row
row; while (result.async_read_one(row, additional_info, yield[ec])) avoiding unnecessary further copies. In principle it would be even possible to parse directly in a custom data structure, for example, when storing json string in the database.
i've developed a small C++17 example of how to work with Input/Output transformers to write the statements more compact and type-safe
the base idea is that the MySQL <-> C++ needs sometimes some sort of conversions and to combine most of the infos at one point so its easier or at least possible to optimize better - the current interface looks very runtime allocation stylish :)
Thanks for sharing. I think I get the idea of "allowing the user to define
custom MySQL <=> C++ mappings".
I'm not really getting the interface that your input/output
transformers would expose, though. Let's take this one, for example:
template <>
struct OutputTransformer<NullAsEmptyString>
{
using value_type = std::string;
static std::string get_value( int /*index_*/ )
{
static std::string x = "hello";
return x;
};
static void get_value( int index_, std::string& value_ )
{
value_ = get_value( index_ );
};
};
I assume this is user-provided code. Where does the user get the
string value from? What does index_ mean in this context?
Let's also take a look at actually using the statements:
My_select my_select( db_connection, "select a, b, c from test
where d == ?1" );
{
// fetch into ref tuple
int some_int{};
float some_float{};
std::string some_string;
my_select( { some_int, some_float, some_string }, { 123 } );
}
How is that different from the following snippet?
resultset r = conn.query("select a, b, c from test where d == ?1" );
tuple
the Input- and Output Transformers help to work with basic types and also with SQL/MySQL special types like Null-string etc. - its not possible to map MySQL types always 1:1 to C++ and back, sometimes you want to behave the transformation different
the Transformers aren't visible when used with basic types
its just an example to promote the Idea: https://pastebin.com/raw/vepbTAKL
the best combination would be some sort of fluent SQL interface like: https://github.com/rbock/sqlpp11
This library is supposed to be a protocol driver library, so it provides primitives close to the MySQL protocol. sqlpp11 is great, but it's a higher level library. I don't think it makes sense trying to incorporate this kind of features here. It would make more sense for a higher level library like sqlpp11 to build on top of Boost.MySQL, instead.
but i still think a plain string+binding interface like Boost.MySql currently got is also needed
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost