diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-20 16:40:06 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-27 17:16:14 +0000 |
commit | b3e4cf093463732b09623cc3309f4f77abecc2ab (patch) | |
tree | b135ea3521ae755ede62910d0af05796e1be1c89 /libpqpp | |
parent | Set cxxflags specifically, not cflags (diff) | |
download | libdbpp-postgresql-b3e4cf093463732b09623cc3309f4f77abecc2ab.tar.bz2 libdbpp-postgresql-b3e4cf093463732b09623cc3309f4f77abecc2ab.tar.xz libdbpp-postgresql-b3e4cf093463732b09623cc3309f4f77abecc2ab.zip |
Set tables in test database to be unlogged, faster (less disk IO) and we don't care about safety in tests
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-mock.cpp | 15 | ||||
-rw-r--r-- | libpqpp/pq-mock.h | 1 |
2 files changed, 16 insertions, 0 deletions
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 <buffer.h> +#include <selectcommand.h> +#include <selectcommandUtil.impl.h> 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<std::string, std::string>()) { + c->execute("ALTER TABLE " + t.value<0>() + "." + t.value<1>() + " SET UNLOGGED"); + } +} + Mock::~Mock() { DropDatabase(); diff --git a/libpqpp/pq-mock.h b/libpqpp/pq-mock.h index e8b7366..0081c5a 100644 --- a/libpqpp/pq-mock.h +++ b/libpqpp/pq-mock.h @@ -15,6 +15,7 @@ namespace PQ { protected: void DropDatabase() const override; + void SetTablesToUnlogged() const; }; } |