#pragma once #include "Statement.h" #include #include namespace db { namespace statements { namespace builder { class InsertStatementBuilder; class AbstractStatementBuilder { protected: Statement &m_statement; explicit AbstractStatementBuilder(Statement &statement) : m_statement(statement) {} public: operator Statement() const { return std::move(m_statement); } }; class StatementBuilder : public AbstractStatementBuilder { public: Statement m_statement; StatementBuilder() : AbstractStatementBuilder{m_statement} { } }; class InsertStatementBuilder : public StatementBuilder { public: explicit InsertStatementBuilder() : StatementBuilder() { } InsertStatementBuilder &table(const std::string &table) { m_statement.body += "INSERT INTO " + table + " "; return *this; } InsertStatementBuilder &columns(const std::string &cols) { m_statement.body += "(" + cols + ")\n"; return *this; } InsertStatementBuilder &values() { m_statement.body += " VALUES "; return *this; } InsertStatementBuilder &row(const std::string &values) { m_statement.body += " (" + values + "),\n"; return *this; } InsertStatementBuilder &row(const std::vector &values) { m_statement.body += " ("; bool first = true; for(auto const& v : values) { if(first) { first = false; } else { m_statement.body += ","; } m_statement.body += v; } m_statement.body += "),\n"; return *this; } InsertStatementBuilder &close() { m_statement.body.pop_back(); m_statement.body.pop_back(); m_statement.body += ";\n"; return *this; } }; } } }