ClickHouse
40 строк · 1.1 Кб
1#include "Utils.h"
2
3#if USE_LIBPQXX
4
5#include <IO/Operators.h>
6#include <IO/WriteHelpers.h>
7
8namespace postgres
9{
10
11ConnectionInfo formatConnectionString(String dbname, String host, UInt16 port, String user, String password)
12{
13DB::WriteBufferFromOwnString out;
14out << "dbname=" << DB::quote << dbname
15<< " host=" << DB::quote << host
16<< " port=" << port
17<< " user=" << DB::quote << user
18<< " password=" << DB::quote << password
19<< " connect_timeout=2";
20return {out.str(), host + ':' + DB::toString(port)};
21}
22
23String getConnectionForLog(const String & host, UInt16 port)
24{
25return host + ":" + DB::toString(port);
26}
27
28String formatNameForLogs(const String & postgres_database_name, const String & postgres_table_name)
29{
30/// Logger for StorageMaterializedPostgreSQL - both db and table names.
31/// Logger for PostgreSQLReplicationHandler and Consumer - either both db and table names or only db name.
32assert(!postgres_database_name.empty());
33if (postgres_table_name.empty())
34return postgres_database_name;
35return postgres_database_name + '.' + postgres_table_name;
36}
37
38}
39
40#endif
41