Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make member variables in table_desc private #2150

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/middle-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ void middle_pgsql_t::table_desc::build_index(
}
}

void middle_pgsql_t::table_desc::create_table(
pg_conn_t const &db_connection) const
{
if (!m_create_table.empty()) {
db_connection.exec(m_create_table);
}
}

void middle_pgsql_t::table_desc::init_max_id(pg_conn_t const &db_connection)
{
auto const qual_name = qualified_name(schema(), name());
Expand Down Expand Up @@ -1315,9 +1323,7 @@ static void table_setup(pg_conn_t const &db_connection,
log_debug("Setting up table '{}'", table.name());
auto const qual_name = qualified_name(table.schema(), table.name());
db_connection.exec("DROP TABLE IF EXISTS {} CASCADE", qual_name);
if (!table.m_create_table.empty()) {
db_connection.exec(table.m_create_table);
}
table.create_table(db_connection);
}

void middle_pgsql_t::start()
Expand Down Expand Up @@ -1730,7 +1736,7 @@ middle_pgsql_t::get_query_instance()

// We use a connection per table to enable the use of COPY
for (auto &table : m_tables) {
for (auto const &query : table.m_prepare_queries) {
for (auto const &query : table.prepare_queries()) {
mid->exec_sql(query);
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/middle-pgsql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,28 @@ struct middle_pgsql_t : public middle_t
///< Open a new database connection and build index on this table.
void build_index(connection_params_t const &connection_params) const;

std::string m_create_table;
std::vector<std::string> m_prepare_queries;
std::vector<std::string> m_create_fw_dep_indexes;

void task_set(std::future<std::chrono::microseconds> &&future)
{
m_task_result.set(std::move(future));
}

std::chrono::microseconds task_wait() { return m_task_result.wait(); }

void create_table(pg_conn_t const &db_connection) const;

void init_max_id(pg_conn_t const &db_connection);

osmid_t max_id() const noexcept { return m_max_id; }

std::vector<std::string> const &prepare_queries() const noexcept
{
return m_prepare_queries;
}

private:
std::string m_create_table;
std::vector<std::string> m_create_fw_dep_indexes;
std::vector<std::string> m_prepare_queries;
std::shared_ptr<db_target_descr_t> m_copy_target;
task_result_t m_task_result;

Expand Down