Roland Bock wrote:
_NULL handling:_ Enabled by the restructured code and spurred by the library quince by Michael Shepanski, sqlpp11 can now calculate which result fields can or cannot be NULL.
Speaking of which, handling NULL for result values has been discussed a lot. The library now has compile-time configurable behavior, you can choose between an std::optional-like interface and mapping NULL to the trivial value of the result type, e.g. 0 for numbers or "" for strings, see also https://github.com/rbock/sqlpp11/wiki/NULL
The way how NULL values are handled is similar to how missing options
are handled in ProgramOptions where if some parameter isn't passed it
may be set to some default value which may be set by the user.
Could it be possible to allow users to define their "trivial" values in
sqlpp?
I'm aware that there is a difference between the two - in sqlpp the
structure is defined in compile-time but ProgramOptions is much more
user friendly at the stage of defining possible options:
desc.add_options()
("help", "produce help message")
("optimization", po::value<int>(&opt)->default_value(10),
"optimization level")
("include-path,I", po::value< vector<string> >(),
"include path")
("input-file", po::value< vector<string> >(), "input file")
;
I'm wondering, could it be possible to implement similar, compile-time
interface in sqlpp, e.g. something similar to MPL?
I'm asking because what the sqlpp library requires is very complicated:
https://github.com/rbock/sqlpp11/blob/master/tests/Sample.h
I'm aware that its purpose is to create a type reflecting required
columns and to use them from the level of C++ but couldn't it be done
simpler?
The first step could be to simplify the process, e.g.:
template <typename T>
struct col_member1
: sqlpp::column {};
with sqlpp::column<> e.g. defined as:
template <
template<typename> class Derived
const char* name,
typename... Traits struct column
{
/*the rest*/
};
Or maybe separate the C++ members from values' definitions and use them
only as a source of C++ members names.
Then define the table structure in MPL-like way:
template <typename T>
struct col_member1 { T col1; };
template <typename T>
struct col_member2 { T col2; };
struct tab1
: sqlpp::table {};
with sqlpp::column<> e.g. defined as:
template <
template<typename> class Base
const char* name,
typename... Traits struct column
: Base
{
/*the rest*/
};
or something similar...
Regards,
Adam