From 4b31f93767163dfd78a5de05f349bc8dfac099e1 Mon Sep 17 00:00:00 2001 From: Ichiro Date: Sat, 12 Feb 2022 22:59:49 +0900 Subject: [PATCH] Add Not In for ORM Criteria (#1176) --- orm_lib/inc/drogon/orm/Criteria.h | 39 +++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/orm_lib/inc/drogon/orm/Criteria.h b/orm_lib/inc/drogon/orm/Criteria.h index 5b1aa398..2b761df3 100644 --- a/orm_lib/inc/drogon/orm/Criteria.h +++ b/orm_lib/inc/drogon/orm/Criteria.h @@ -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 &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 &&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("$?");