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 | 1c0f59d77d84a4c405bfa561bd03de1a369da530 (patch) | |
tree | f6911df2775cb9a9cb4b7b43a9aab970960339a9 /libpqpp | |
parent | Set cxxflags specifically, not cflags (diff) | |
download | libdbpp-postgresql-1c0f59d77d84a4c405bfa561bd03de1a369da530.tar.bz2 libdbpp-postgresql-1c0f59d77d84a4c405bfa561bd03de1a369da530.tar.xz libdbpp-postgresql-1c0f59d77d84a4c405bfa561bd03de1a369da530.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; }; } |