63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
#ifndef QUERY_SESSION_HPP
|
|
#define QUERY_SESSION_HPP
|
|
|
|
#include "matador/sql/column_generator.hpp"
|
|
#include "matador/sql/connection.hpp"
|
|
#include "matador/sql/connection_pool.hpp"
|
|
#include "matador/sql/query_builder.hpp"
|
|
#include "matador/sql/query_intermediates.hpp"
|
|
#include "matador/sql/table_repository.hpp"
|
|
|
|
#include <unordered_map>
|
|
|
|
namespace matador::sql {
|
|
|
|
class dialect;
|
|
|
|
class session
|
|
{
|
|
public:
|
|
explicit session(connection_pool<connection> &pool);
|
|
|
|
query_create_intermediate create();
|
|
query_drop_intermediate drop();
|
|
template < class Type >
|
|
query_select_intermediate select()
|
|
{
|
|
return query_select_intermediate{*this, column_generator::generate<Type>(table_repository_)};
|
|
}
|
|
query_select_intermediate select(std::initializer_list<column> columns);
|
|
query_insert_intermediate insert();
|
|
query_update_intermediate update(const std::string &table);
|
|
query_delete_intermediate remove();
|
|
|
|
[[nodiscard]] query_result<record> fetch(const query &q) const;
|
|
// [[nodiscard]] query_result<record> fetch(const std::string &sql) const;
|
|
[[nodiscard]] std::pair<size_t, std::string> execute(const std::string &sql) const;
|
|
|
|
template<typename Type>
|
|
void attach(const std::string &table_name)
|
|
{
|
|
table_repository_.attach<Type>(table_name);
|
|
}
|
|
|
|
[[nodiscard]] const table_repository& tables() const;
|
|
|
|
const class dialect& dialect() const;
|
|
|
|
private:
|
|
friend class query_select_finish;
|
|
|
|
[[nodiscard]] std::unique_ptr<query_result_impl> fetch(const std::string &sql) const;
|
|
|
|
private:
|
|
connection_pool<connection> &pool_;
|
|
const class dialect &dialect_;
|
|
|
|
table_repository table_repository_;
|
|
mutable std::unordered_map<std::string, record> prototypes_;
|
|
};
|
|
|
|
}
|
|
#endif //QUERY_SESSION_HPP
|