summaryrefslogtreecommitdiff
path: root/lib/output/pq/pqConn.h
blob: 5c9effb6ffc6ed96b41286dc24cea4de8a9ac39f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef MYGRATE_OUTPUT_PQ_PQCONN_H
#define MYGRATE_OUTPUT_PQ_PQCONN_H

#include <cstddef>
#include <dbConn.h>
#include <functional>
#include <initializer_list>
#include <libpq-fe.h>
#include <map>
#include <memory>
#include <string>

namespace MyGrate {
	class DbValue;
}
namespace MyGrate::Output::Pq {
	class PqConn : public DbConn {
	public:
		static constexpr auto paramMode {ParamMode::DollarNum};

		explicit PqConn(const char * const str);
		virtual ~PqConn() = default;

		void query(const char * const) override;
		void query(const char * const, const std::initializer_list<DbValue> &) override;

		DbPrepStmtPtr prepare(const char * const, std::size_t nParams) override;

	private:
		static void notice_processor(void *, const char *);
		virtual void notice_processor(const char *) const;

		std::unique_ptr<PGconn, decltype(&PQfinish)> const conn;

		friend class PqPrepStmt;
		std::map<std::string, std::string, std::less<>> stmts;
	};
}

#endif