|
42 | 42 | #include "options.hpp" |
43 | 43 | #include "osmtypes.hpp" |
44 | 44 | #include "pgsql-helper.hpp" |
| 45 | +#include "template.hpp" |
45 | 46 | #include "util.hpp" |
46 | 47 |
|
47 | 48 | namespace { |
@@ -72,37 +73,44 @@ void load_id_list(pg_conn_t const &db_connection, std::string const &table, |
72 | 73 |
|
73 | 74 | std::string build_sql(options_t const &options, std::string const &templ) |
74 | 75 | { |
75 | | - std::string const using_tablespace{options.tblsslim_index.empty() |
76 | | - ? "" |
77 | | - : "USING INDEX TABLESPACE " + |
78 | | - options.tblsslim_index}; |
79 | | - |
80 | 76 | std::string const schema = "\"" + options.middle_dbschema + "\"."; |
81 | 77 |
|
82 | | - return fmt::format( |
83 | | - fmt::runtime(templ), fmt::arg("prefix", options.prefix), |
84 | | - fmt::arg("schema", schema), |
85 | | - fmt::arg("unlogged", options.droptemp ? "UNLOGGED" : ""), |
86 | | - fmt::arg("using_tablespace", using_tablespace), |
87 | | - fmt::arg("data_tablespace", tablespace_clause(options.tblsslim_data)), |
88 | | - fmt::arg("index_tablespace", tablespace_clause(options.tblsslim_index)), |
89 | | - fmt::arg("way_node_index_id_shift", 5), |
90 | | - fmt::arg("attribute_columns_definition", |
91 | | - options.extra_attributes ? " created timestamp with time zone," |
92 | | - " version int4," |
93 | | - " changeset_id int4," |
94 | | - " user_id int4," |
95 | | - : ""), |
96 | | - fmt::arg("attribute_columns_use", |
97 | | - options.extra_attributes |
98 | | - ? ", EXTRACT(EPOCH FROM created) AS created, version, " |
99 | | - "changeset_id, user_id, u.name" |
100 | | - : ""), |
101 | | - fmt::arg("users_table_access", |
102 | | - options.extra_attributes |
103 | | - ? "LEFT JOIN " + schema + '"' + options.prefix + |
104 | | - "_users\" u ON o.user_id = u.id" |
105 | | - : "")); |
| 78 | + params_t params; |
| 79 | + params.set("prefix", options.prefix); |
| 80 | + params.set("schema", schema); |
| 81 | + params.set("unlogged", options.droptemp ? "UNLOGGED" : ""); |
| 82 | + params.set("data_tablespace", tablespace_clause(options.tblsslim_data)); |
| 83 | + params.set("index_tablespace", tablespace_clause(options.tblsslim_index)); |
| 84 | + params.set("way_node_index_id_shift", 5); |
| 85 | + |
| 86 | + if (options.tblsslim_index.empty()) { |
| 87 | + params.set("using_tablespace", ""); |
| 88 | + } else { |
| 89 | + params.set("using_tablespace", |
| 90 | + "USING INDEX TABLESPACE " + options.tblsslim_index); |
| 91 | + } |
| 92 | + |
| 93 | + if (options.extra_attributes) { |
| 94 | + params.set("attribute_columns_definition", |
| 95 | + " created timestamp with time zone," |
| 96 | + " version int4," |
| 97 | + " changeset_id int4," |
| 98 | + " user_id int4,"); |
| 99 | + params.set("attribute_columns_use", |
| 100 | + ", EXTRACT(EPOCH FROM created) AS created, version, " |
| 101 | + "changeset_id, user_id, u.name"); |
| 102 | + params.set("users_table_access", "LEFT JOIN " + schema + '"' + |
| 103 | + options.prefix + |
| 104 | + "_users\" u ON o.user_id = u.id"); |
| 105 | + } else { |
| 106 | + params.set("attribute_columns_definition", ""); |
| 107 | + params.set("attribute_columns_use", ""); |
| 108 | + params.set("users_table_access", ""); |
| 109 | + } |
| 110 | + |
| 111 | + template_t sql_template{templ}; |
| 112 | + sql_template.set_params(params); |
| 113 | + return sql_template.render(); |
106 | 114 | } |
107 | 115 |
|
108 | 116 | std::vector<std::string> build_sql(options_t const &options, |
|
0 commit comments