Fledge
An open source edge computing platform for industrial users
where.h
1 #ifndef _WHERE_H
2 #define _WHERE_H
3 /*
4  * Fledge storage client.
5  *
6  * Copyright (c) 2018 OSisoft, LLC
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch, Massimiliano Pinto
11  */
12 #include <string>
13 #include <vector>
14 #include <stdexcept>
15 
16 typedef enum Conditional {
17  Older,
18  Newer,
19  Equals,
20  NotEquals,
21  GreaterThan,
22  LessThan,
23  In,
24  IsNull,
25  NotNull
26 } Condition;
27 
31 class Where {
32  public:
33  Where(const std::string& column, const Condition condition, const std::string& value) :
34  m_column(column), m_condition(condition), m_and(0), m_or(0)
35  {
36  if (condition != In)
37  {
38  m_value = value;
39  }
40  else
41  {
42  m_in.push_back(value);
43  }
44  };
45  Where(const std::string& column, const Condition condition, const std::string& value, Where *andCondition) :
46  m_column(column), m_condition(condition), m_and(andCondition), m_or(0)
47  {
48  if (condition != In)
49  {
50  m_value = value;
51  }
52  else
53  {
54  m_in.push_back(value);
55  }
56  };
57  Where(const std::string& column, const Condition condition) :
58  m_column(column), m_condition(condition), m_and(0), m_or(0)
59  {
60  if (condition != IsNull && condition != NotNull)
61  {
62  throw std::runtime_error("Missing value in where clause");
63  }
64  };
65  Where(const std::string& column, const Condition condition, Where *andCondition) :
66  m_column(column), m_condition(condition), m_and(andCondition), m_or(0)
67  {
68  if (condition != IsNull && condition != NotNull)
69  {
70  throw std::runtime_error("Missing value in where clause");
71  }
72  };
73  ~Where();
74  void andWhere(Where *condition) { m_and = condition; };
75  void orWhere(Where *condition) { m_or = condition; };
76  void addIn(const std::string& value)
77  {
78  if (m_condition == In)
79  {
80  m_in.push_back(value);
81  }
82  };
83  const std::string toJSON() const;
84  private:
85  Where(const Where&);
86  Where& operator=(Where const&);
87  const std::string m_column;
88  const Condition m_condition;
89  std::string m_value;
90  Where *m_and;
91  Where *m_or;
92  std::vector<std::string>
93  m_in;
94 };
95 #endif
96 
~Where()
Where clause destructor.
Definition: where.cpp:20
const std::string toJSON() const
Return the JSON payload for a where clause.
Definition: where.cpp:35
Where clause in a selection of records.
Definition: where.h:31