Modify model creation
This commit is contained in:
parent
5b26d4587b
commit
8ed5e19f46
|
@ -86,6 +86,7 @@ void create_model::createModelClassFromPG(const std::string &path, const DbClien
|
|||
{
|
||||
auto row = r[i];
|
||||
ColumnInfo info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
info._index = i;
|
||||
info._dbType = "pg";
|
||||
info._colName = row["column_name"].as<std::string>();
|
||||
|
@ -312,6 +313,7 @@ void create_model::createModelClassFromMysql(const std::string &path, const DbCl
|
|||
if (!isNull)
|
||||
{
|
||||
ColumnInfo info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
info._index = i;
|
||||
info._dbType = "pg";
|
||||
info._colName = field;
|
||||
|
@ -361,6 +363,14 @@ void create_model::createModelClassFromMysql(const std::string &path, const DbCl
|
|||
{
|
||||
info._colType = "u" + info._colType;
|
||||
}
|
||||
if (!defaultVal.empty())
|
||||
{
|
||||
info._hasDefaultVal = true;
|
||||
}
|
||||
if (extra.find("auto_") == 0)
|
||||
{
|
||||
info._isAutoVal = true;
|
||||
}
|
||||
cols.push_back(std::move(info));
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ class Mapper
|
|||
|
||||
Mapper(const DbClientPtr &client) : _client(client) {}
|
||||
|
||||
typedef typename internal::Traits<T,!std::is_same<typename T::PrimaryKeyType, void>::value>::type TraitsPKType;
|
||||
typedef typename internal::Traits<T, !std::is_same<typename T::PrimaryKeyType, void>::value>::type TraitsPKType;
|
||||
|
||||
T findByPrimaryKey(const TraitsPKType &key) noexcept(false);
|
||||
|
||||
void findByPrimaryKey(const TraitsPKType &key,
|
||||
const SingleRowCallback &rcb,
|
||||
const ExceptionCallback &ecb) noexcept;
|
||||
const SingleRowCallback &rcb,
|
||||
const ExceptionCallback &ecb) noexcept;
|
||||
|
||||
std::future<T> findFutureByPrimaryKey(const TraitsPKType &key) noexcept;
|
||||
|
||||
|
@ -1039,23 +1039,48 @@ template <typename T>
|
|||
inline std::string Mapper<T>::replaceSqlPlaceHolder(const std::string &sqlStr, const std::string &holderStr) const
|
||||
{
|
||||
///FIXME add mysql support
|
||||
std::string::size_type startPos = 0;
|
||||
std::string::size_type pos;
|
||||
std::stringstream ret;
|
||||
size_t phCount = 1;
|
||||
do
|
||||
if (_client->type() == ClientType::PostgreSQL)
|
||||
{
|
||||
pos = sqlStr.find(holderStr, startPos);
|
||||
if (pos == std::string::npos)
|
||||
std::string::size_type startPos = 0;
|
||||
std::string::size_type pos;
|
||||
std::stringstream ret;
|
||||
size_t phCount = 1;
|
||||
do
|
||||
{
|
||||
ret << sqlStr.substr(startPos);
|
||||
return ret.str();
|
||||
}
|
||||
ret << sqlStr.substr(startPos, pos - startPos);
|
||||
ret << "$";
|
||||
ret << phCount++;
|
||||
startPos = pos + holderStr.length();
|
||||
} while (1);
|
||||
pos = sqlStr.find(holderStr, startPos);
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
ret << sqlStr.substr(startPos);
|
||||
return ret.str();
|
||||
}
|
||||
ret << sqlStr.substr(startPos, pos - startPos);
|
||||
ret << "$";
|
||||
ret << phCount++;
|
||||
startPos = pos + holderStr.length();
|
||||
} while (1);
|
||||
}
|
||||
else if (_client->type() == ClientType::Mysql)
|
||||
{
|
||||
std::string::size_type startPos = 0;
|
||||
std::string::size_type pos;
|
||||
std::stringstream ret;
|
||||
do
|
||||
{
|
||||
pos = sqlStr.find(holderStr, startPos);
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
ret << sqlStr.substr(startPos);
|
||||
return ret.str();
|
||||
}
|
||||
ret << sqlStr.substr(startPos, pos - startPos);
|
||||
ret << "?";
|
||||
startPos = pos + holderStr.length();
|
||||
} while (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sqlStr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orm
|
||||
|
|
Loading…
Reference in New Issue