Skip to content

Commit 104d53a

Browse files
committed
cleanup
1 parent 2b45556 commit 104d53a

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/fill-postgresql.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ inline string begin_array(bool bulk) {
133133
return "array[";
134134
}
135135

136-
inline string end_array(bool bulk, pqxx::work& t, const std::string& schema, const std::string& table) {
136+
inline string end_array(bool bulk, pqxx::work& t, const std::string& schema, const std::string& type) {
137137
if (bulk)
138138
return "}";
139139
else
140-
return "]::" + t.quote_name(schema) + "." + t.quote_name(table) + "[]";
140+
return "]::" + t.quote_name(schema) + "." + t.quote_name(type) + "[]";
141141
}
142142

143143
inline string begin_object_in_array(bool bulk) {
@@ -1053,18 +1053,12 @@ struct session : enable_shared_from_this<session> {
10531053
fill_value(bulk, nested_bulk, t, base_name + field.name + "_", fields, values, bin, f);
10541054
} else if (field.type->array_of && field.type->array_of->filled_struct) {
10551055
fields += ", " + t.quote_name(base_name + field.name);
1056-
if (bulk)
1057-
values += "\t{";
1058-
else
1059-
values += ", array[";
1056+
values += sep(bulk) + begin_array(bulk);
10601057
uint32_t n = read_varuint32(bin);
10611058
for (uint32_t i = 0; i < n; ++i) {
10621059
if (i)
10631060
values += ",";
1064-
if (bulk)
1065-
values += "\"(";
1066-
else
1067-
values += "(";
1061+
values += begin_object_in_array(bulk);
10681062
string struct_fields;
10691063
string struct_values;
10701064
for (auto& f : field.type->array_of->fields)
@@ -1073,15 +1067,9 @@ struct session : enable_shared_from_this<session> {
10731067
values += struct_values.substr(1);
10741068
else
10751069
values += struct_values.substr(2);
1076-
if (bulk)
1077-
values += ")\"";
1078-
else
1079-
values += ")";
1070+
values += end_object_in_array(bulk);
10801071
}
1081-
if (bulk)
1082-
values += "}";
1083-
else
1084-
values += "]::" + t.quote_name(schema) + "." + t.quote_name(field.type->array_of->name) + "[]";
1072+
values += end_array(bulk, t, schema, field.type->array_of->name);
10851073
} else {
10861074
auto abi_type = field.type->name;
10871075
bool is_optional = false;
@@ -1146,12 +1134,7 @@ struct session : enable_shared_from_this<session> {
11461134
values += sep(bulk) + null_value(bulk);
11471135
}
11481136

1149-
if (bulk) {
1150-
write_stream(block_index, t, "block_info", values);
1151-
} else {
1152-
string query = "insert into " + t.quote_name(schema) + ".block_info(" + fields + ") values (" + values + ")";
1153-
pipeline.insert(query);
1154-
}
1137+
write(block_index, t, pipeline, bulk, "block_info", fields, values);
11551138
} // receive_block
11561139

11571140
void receive_deltas(uint32_t block_num, input_buffer buf, bool bulk, pqxx::work& t, pqxx::pipeline& pipeline) {

0 commit comments

Comments
 (0)