Add Not In for ORM Criteria (#1176)

This commit is contained in:
Ichiro 2022-02-12 22:59:49 +09:00 committed by GitHub
parent 3c785326c6
commit 4b31f93767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 10 deletions

View File

@ -40,6 +40,7 @@ enum class CompareOperator
LE,
Like,
In,
NotIn,
IsNull,
IsNotNull
};
@ -107,8 +108,6 @@ class DROGON_EXPORT Criteria
case CompareOperator::Like:
conditionString_ += " like $?";
break;
case CompareOperator::IsNull:
case CompareOperator::IsNotNull:
default:
break;
}
@ -123,11 +122,21 @@ class DROGON_EXPORT Criteria
const CompareOperator &opera,
const std::vector<T> &args)
{
assert(opera == CompareOperator::In && args.size() > 0);
conditionString_ = colName + " in (";
for (size_t i = 0; i < args.size(); ++i)
const auto argsSize = args.size();
assert(((opera == CompareOperator::In) ||
(opera == CompareOperator::NotIn)) &&
(argsSize > 0));
if (opera == CompareOperator::In)
{
if (i < args.size() - 1)
conditionString_ = colName + " in (";
}
else if (opera == CompareOperator::NotIn)
{
conditionString_ = colName + " not in (";
}
for (size_t i = 0; i < argsSize; ++i)
{
if (i < (argsSize - 1))
conditionString_.append("$?,");
else
conditionString_.append("$?");
@ -146,11 +155,21 @@ class DROGON_EXPORT Criteria
const CompareOperator &opera,
std::vector<T> &&args)
{
assert(opera == CompareOperator::In && args.size() > 0);
conditionString_ = colName + " in (";
for (size_t i = 0; i < args.size(); ++i)
const auto argsSize = args.size();
assert(((opera == CompareOperator::In) ||
(opera == CompareOperator::NotIn)) &&
(argsSize > 0));
if (opera == CompareOperator::In)
{
if (i < args.size() - 1)
conditionString_ = colName + " in (";
}
else if (opera == CompareOperator::NotIn)
{
conditionString_ = colName + " not in (";
}
for (size_t i = 0; i < argsSize; ++i)
{
if (i < (argsSize - 1))
conditionString_.append("$?,");
else
conditionString_.append("$?");