From 1c0f59d77d84a4c405bfa561bd03de1a369da530 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 20 Dec 2016 16:40:06 +0000 Subject: Set tables in test database to be unlogged, faster (less disk IO) and we don't care about safety in tests --- libpqpp/pq-mock.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libpqpp/pq-mock.cpp') diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp index db7eafb..30f14aa 100644 --- a/libpqpp/pq-mock.cpp +++ b/libpqpp/pq-mock.cpp @@ -1,6 +1,8 @@ #include "pq-mock.h" #include "pq-connection.h" #include +#include +#include namespace PQ { @@ -9,6 +11,7 @@ Mock::Mock(const std::string & masterdb, const std::string & name, const std::ve { CreateNewDatabase(); PlaySchemaScripts(ss); + SetTablesToUnlogged(); } DB::Connection * @@ -17,6 +20,18 @@ Mock::openConnection() const return new Connection(stringbf("user=postgres dbname=%s", testDbName)); } +void +Mock::SetTablesToUnlogged() const +{ + auto c = DB::ConnectionPtr(openConnection()); + auto s = c->select("SELECT schemaname, tablename FROM pg_catalog.pg_tables WHERE schemaname NOT IN (?, ?)"); + s->bindParamS(0, "pg_catalog"); + s->bindParamS(1, "information_schema"); + for (const auto & t : s->as()) { + c->execute("ALTER TABLE " + t.value<0>() + "." + t.value<1>() + " SET UNLOGGED"); + } +} + Mock::~Mock() { DropDatabase(); -- cgit v1.2.3