Codegen. DbClient. Introduce PARAMS_DTO macro.

This commit is contained in:
lganzzzo 2020-08-14 03:53:08 +03:00
parent 460bfc4b03
commit 25d21ebae1
3 changed files with 41 additions and 10 deletions

View File

@ -130,10 +130,14 @@ void Serializer::serInt8(OutputData& outData, v_int64 value) {
// Serializer functions
void Serializer::serializeString(OutputData& outData, const oatpp::Void& polymorph) {
base::StrBuffer* buff = static_cast<base::StrBuffer*>(polymorph.get());
outData.data = buff->c_str();
outData.dataSize = buff->getSize();
outData.dataFormat = 1;
if(polymorph) {
base::StrBuffer *buff = static_cast<base::StrBuffer *>(polymorph.get());
outData.data = buff->c_str();
outData.dataSize = buff->getSize();
outData.dataFormat = 1;
} else {
serNull(outData);
}
}
void Serializer::serializeInt8(OutputData& outData, const oatpp::Void& polymorph) {

View File

@ -35,7 +35,7 @@ data::share::StringTemplate::Variable Parser::parseIdentifier(parser::Caret& car
auto label = caret.putLabel();
while(caret.canContinue()) {
v_char8 a = *caret.getCurrData();
bool isAllowedChar = (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9') || (a == '_');
bool isAllowedChar = (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9') || (a == '_') || (a == '.');
if(!isAllowedChar) {
result.posEnd = caret.getPosition() - 1;
result.name = label.toString();

View File

@ -37,6 +37,7 @@ class Ints : public oatpp::DTO {
#include OATPP_CODEGEN_END(DTO)
#include OATPP_CODEGEN_BEGIN(DTO)
#include OATPP_CODEGEN_BEGIN(DbClient)
class MyClient : public oatpp::orm::DbClient {
@ -62,10 +63,27 @@ public:
QUERY(insertStrs,
"INSERT INTO test_strs "
"(f_str1, f_str2, f_str3) VALUES "
"(:f_str1, :f_str2, :f_str3);",
PARAM(oatpp::String, f_str1),
PARAM(oatpp::String, f_str2),
PARAM(oatpp::String, f_str3))
"(:f_str1.param, :f_str2.param, :f_str3.param);",
PARAM(oatpp::String, f_str1, "f_str1.param"),
PARAM(oatpp::String, f_str2, "f_str2.param"),
PARAM(oatpp::String, f_str3, "f_str3.param"))
class InsertStrsDto : public oatpp::DTO {
DTO_INIT(InsertStrsDto, DTO)
DTO_FIELD(oatpp::String, f_str1);
DTO_FIELD(oatpp::String, f_str2);
DTO_FIELD(oatpp::String, f_str3);
};
QUERY(insertStrsWithDtoParams,
"INSERT INTO test_strs "
"(f_str1, f_str2, f_str3) VALUES "
"(:dto.f_str1, :dto.f_str2, :dto.f_str3);",
PARAMS_DTO(oatpp::Object<InsertStrsDto>, rowDto, "dto"))
QUERY(selectStrs, "SELECT * FROM test_strs")
@ -91,6 +109,7 @@ public:
};
#include OATPP_CODEGEN_END(DbClient)
#include OATPP_CODEGEN_END(DTO)
class Test : public oatpp::test::UnitTest {
public:
@ -119,10 +138,18 @@ public:
//client.insertFloats(0.32, 0.64, connection);
//client.insertFloats(-0.32, -0.64, connection);
// client.insertStrs("Hello", "World", "Oat++");
// client.insertStrs("Hello", "Dot", "Param");
// client.insertStrs("Hello", "World", "oatpp");
// client.insertStrs("Yeah", "Ops", "!!!");
{
auto row = MyClient::InsertStrsDto::createShared();
row->f_str1 = "A";
row->f_str2 = "B";
row->f_str3 = "C";
client.insertStrsWithDtoParams(row);
}
{
auto res = client.selectStrs();