-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add draft of WHERE cluse in query class
- Loading branch information
Showing
6 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace orm::query | ||
{ | ||
class Condition | ||
{ | ||
enum class Operator | ||
{ | ||
EQUAL, | ||
NOT_EQUAL, | ||
GREATER, | ||
GREATER_OR_EQUAL, | ||
LESS, | ||
LESS_OR_EQUAL, | ||
LIKE, | ||
NOT_LIKE, | ||
IS_NULL, | ||
IS_NOT_NULL | ||
}; | ||
|
||
public: | ||
Condition(std::string columnName); | ||
|
||
// auto operator==(const std::string& value) -> Condition&; | ||
// | ||
// auto operator!=(const std::string& value) -> Condition&; | ||
// | ||
// auto operator>(const std::string& value) -> Condition&; | ||
// | ||
// auto operator>=(const std::string& value) -> Condition&; | ||
// | ||
// auto operator<(const std::string& value) -> Condition&; | ||
// | ||
// auto operator<=(const std::string& value) -> Condition&; | ||
|
||
auto like(const std::string& value) -> Condition&; | ||
|
||
auto notLike(const std::string& value) -> Condition&; | ||
|
||
auto isNull() -> Condition&; | ||
|
||
auto isNotNull() -> Condition&; | ||
|
||
private: | ||
std::string columnName; | ||
|
||
Operator operatorType; | ||
|
||
std::string comparisonValue; | ||
}; | ||
} // namespace orm::query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "orm-cxx/query/Condition.hpp" | ||
|
||
namespace orm::query | ||
{ | ||
Condition::Condition(std::string columnName) : columnName{std::move(columnName)} {} | ||
|
||
auto Condition::like(const std::string& value) -> Condition& | ||
{ | ||
operatorType = Operator::LIKE; | ||
comparisonValue = value; | ||
return *this; | ||
} | ||
|
||
auto Condition::notLike(const std::string& value) -> Condition& | ||
{ | ||
operatorType = Operator::NOT_LIKE; | ||
comparisonValue = value; | ||
return *this; | ||
} | ||
|
||
auto Condition::isNull() -> Condition& | ||
{ | ||
operatorType = Operator::IS_NULL; | ||
return *this; | ||
} | ||
|
||
auto Condition::isNotNull() -> Condition& | ||
{ | ||
operatorType = Operator::IS_NOT_NULL; | ||
return *this; | ||
} | ||
} // namespace orm::query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "orm-cxx/query/Condition.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace | ||
{ | ||
|
||
} | ||
|
||
class ConditionTest : public ::testing::Test | ||
{ | ||
}; | ||
|
||
TEST_F(ConditionTest, shouldCreateCondition) | ||
{ | ||
orm::query::Condition condition{"test"}; | ||
} | ||
|
||
TEST_F(ConditionTest, shouldSetLikeCondition) | ||
{ | ||
orm::query::Condition condition{"test"}; | ||
condition.like("value"); | ||
} | ||
|
||
TEST_F(ConditionTest, shouldSetNotLikeCondition) | ||
{ | ||
orm::query::Condition condition{"test"}; | ||
condition.notLike("value"); | ||
} | ||
|
||
TEST_F(ConditionTest, shouldSetIsNullCondition) | ||
{ | ||
orm::query::Condition condition{"test"}; | ||
condition.isNull(); | ||
} | ||
|
||
TEST_F(ConditionTest, shouldSetIsNotNullCondition) | ||
{ | ||
orm::query::Condition condition{"test"}; | ||
condition.isNotNull(); | ||
} |