query.cpp 1.11 KB
Newer Older
1 2 3
#include <database/query.hpp>
#include <database/column.hpp>

louiz’'s avatar
louiz’ committed
4 5 6 7 8
void actual_bind(Statement& statement, const std::string& value, int index)
{
  statement.bind_text(index, value);
}

9
void actual_bind(Statement& statement, const std::int64_t& value, int index)
louiz’'s avatar
louiz’ committed
10 11 12 13
{
  statement.bind_int64(index, value);
}

14
void actual_bind(Statement& statement, const OptionalBool& value, int index)
louiz’'s avatar
louiz’ committed
15
{
16
  if (!value.is_set)
louiz’'s avatar
louiz’ committed
17
    statement.bind_int64(index, 0);
18
  else if (value.value)
louiz’'s avatar
louiz’ committed
19 20 21 22 23
    statement.bind_int64(index, 1);
  else
    statement.bind_int64(index, -1);
}

24 25 26 27
void actual_add_param(Query& query, const std::string& val)
{
  query.params.push_back(val);
}
28

29
void actual_add_param(Query& query, const OptionalBool& val)
30
{
31
  if (!val.is_set)
32
    query.params.push_back("0");
33
  else if (val.value)
34 35 36
    query.params.push_back("1");
  else
    query.params.push_back("-1");
37 38 39 40 41 42 43 44 45 46
}

Query& operator<<(Query& query, const char* str)
{
  query.body += str;
  return query;
}

Query& operator<<(Query& query, const std::string& str)
{
louiz’'s avatar
louiz’ committed
47 48
  query.body += "$" + std::to_string(query.current_param);
  query.current_param++;
49 50 51
  actual_add_param(query, str);
  return query;
}