Skip to content

Commit f6b2a97

Browse files
authored
Output is now much more compact allowing for easier comparison of tables with lots of columns. Ex: even just 1 change in a table with 200 columns would output more than 400 lines before
1 parent 53cabbb commit f6b2a97

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

db_diff/__init__.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,22 @@ def human_text(result, key=None, current=None, extras=None):
141141
summary.append(fragment + "\n")
142142
change_blocks = []
143143
for details in result["changed"]:
144-
block = []
145-
block.append(" {}: {}".format(key, details["key"]))
146-
for field, (prev_value, current_value) in details["changes"].items():
147-
block.append(
148-
' {}: "{}" => "{}"'.format(field, prev_value, current_value)
149-
)
144+
# Compact: key: field1: "old" => "new", field2: "old" => "new", ...
145+
changes_str = ", ".join(
146+
f'{field}: "{prev}" => "{curr}"'
147+
for field, (prev, curr) in details["changes"].items()
148+
)
149+
block = [f" {key}: {details['key']} | {changes_str}"]
150150
if extras:
151151
current_item = current[details["key"]]
152152
block.append(human_extras(current_item, extras))
153-
block.append("")
154-
change_blocks.append("\n".join(block))
155153
if details.get("unchanged"):
156-
block = []
157-
block.append(" Unchanged:")
158-
for field, value in details["unchanged"].items():
159-
block.append(' {}: "{}"'.format(field, value))
160-
block.append("")
161-
change_blocks.append("\n".join(block))
154+
unchanged_str = ", ".join(
155+
f'{field}: "{value}"'
156+
for field, value in details["unchanged"].items()
157+
)
158+
block.append(f" Unchanged: {unchanged_str}")
159+
change_blocks.append("\n".join(block))
162160
summary.append("\n".join(change_blocks))
163161
if result["added"]:
164162
fragment = "{} rows added".format(len(result["added"]))
@@ -171,7 +169,7 @@ def human_text(result, key=None, current=None, extras=None):
171169
if extras:
172170
to_append += "\n" + human_extras(row, extras)
173171
rows.append(to_append)
174-
summary.append("\n\n".join(rows))
172+
summary.append("\n".join(rows))
175173
summary.append("")
176174
if result["removed"]:
177175
fragment = "{} rows removed".format(len(result["removed"]))
@@ -184,16 +182,14 @@ def human_text(result, key=None, current=None, extras=None):
184182
if extras:
185183
to_append += "\n" + human_extras(row, extras)
186184
rows.append(to_append)
187-
summary.append("\n\n".join(rows))
185+
summary.append("\n".join(rows))
188186
summary.append("")
189187
return (", ".join(title) + "\n\n" + ("\n".join(summary))).strip()
190188

191189

192190
def human_row(row, prefix=""):
193-
bits = []
194-
for key, value in row.items():
195-
bits.append("{}{}: {}".format(prefix, key, value))
196-
return "\n".join(bits)
191+
# Compact: key1=value1, key2=value2, ...
192+
return prefix + ", ".join(f"{k}={v}" for k, v in row.items())
197193

198194

199195
def human_extras(row, extras):

0 commit comments

Comments
 (0)