From 9b81cdebba95f1b6e687191c630c1f8f6cf0df16 Mon Sep 17 00:00:00 2001
From: znone <glyc@sina.com.cn>
Date: Thu, 25 Mar 2021 12:44:30 +0000
Subject: [PATCH] PostgreSQL: Support asynchronous operation Fix bug in different versions of asio

---
 include/qtl_postgres_pool.hpp |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/include/qtl_postgres_pool.hpp b/include/qtl_postgres_pool.hpp
index 5f8b59c..815ee3c 100644
--- a/include/qtl_postgres_pool.hpp
+++ b/include/qtl_postgres_pool.hpp
@@ -38,6 +38,32 @@
 	std::string m_password;
 };
 
+template<typename EventLoop>
+class async_pool : public qtl::async_pool<async_pool<EventLoop>, EventLoop, async_connection>
+{
+	typedef qtl::async_pool<async_pool<EventLoop>, EventLoop, async_connection> base_class;
+public:
+	async_pool(EventLoop& ev) : base_class(ev) { }
+	virtual ~async_pool() { }
+
+	template<typename Handler>
+	void new_connection(EventLoop& ev, Handler&& handler) throw()
+	{
+		async_connection* db = new async_connection;
+		db->open(ev, [this, handler, db](const postgres::error& e) mutable {
+			if (e)
+			{
+				delete db;
+				db = nullptr;
+			}
+			handler(e, db);
+		}, m_params);
+	}
+
+protected:
+	std::map<std::string, std::string> m_params;
+};
+
 }
 
 }

--
Gitblit v1.9.3