You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

  1. #include "InsertStatementBuilder.h"
  2. namespace db {
  3. namespace statements {
  4. namespace builder {
  5. InsertStatementBuilder &InsertStatementBuilder::table(const std::string &table) {
  6. m_statement.body += "INSERT INTO " + table + " ";
  7. return *this;
  8. }
  9. InsertStatementBuilder &InsertStatementBuilder::columns(const std::string &cols) {
  10. m_statement.body += "(" + cols + ")\n";
  11. return *this;
  12. }
  13. InsertStatementBuilder &InsertStatementBuilder::values() {
  14. m_statement.body += " VALUES ";
  15. return *this;
  16. }
  17. InsertStatementBuilder &InsertStatementBuilder::row(const std::string &values) {
  18. m_statement.body += " (" + values + "),\n";
  19. return *this;
  20. }
  21. InsertStatementBuilder &InsertStatementBuilder::row(const std::vector<std::string> &values) {
  22. m_statement.body += " (";
  23. bool first = true;
  24. for(auto const& v : values) {
  25. if(first) { first = false; } else { m_statement.body += ","; }
  26. m_statement.body += v;
  27. }
  28. m_statement.body += "),\n";
  29. return *this;
  30. }
  31. InsertStatementBuilder &InsertStatementBuilder::close() {
  32. m_statement.body.pop_back();
  33. m_statement.body.pop_back();
  34. m_statement.body += ";\n";
  35. return *this;
  36. }
  37. }
  38. }
  39. }