Skip to content

Commit

Permalink
Merge pull request #60 from ontodev/new-view-forked-from-undo-redo
Browse files Browse the repository at this point in the history
Create new user-friendly view
  • Loading branch information
lmcmicu authored Nov 3, 2023
2 parents 8805614 + 8e17891 commit f4d1528
Show file tree
Hide file tree
Showing 7 changed files with 779 additions and 1,012 deletions.
26 changes: 2 additions & 24 deletions scripts/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,12 @@ def export_data(cursor, is_sqlite, args):
columns_info = get_column_order_and_info_for_postgres(cursor, table)
unsorted_columns = columns_info["unsorted_columns"]

select = []
for column in unsorted_columns:
if column == "row_number":
select.append(f'"{column}"')
else:
cast = "" if is_sqlite else "::TEXT"
is_clause = "IS" if is_sqlite else "IS NOT DISTINCT FROM"
select.append(
f"""
CASE
WHEN "{column}" {is_clause} NULL THEN (
SELECT value
FROM "message"
WHERE "row" = "row_number"
AND "column" = '{column}'
AND "table" = '{table}'
ORDER BY "message_id" DESC
LIMIT 1
)
ELSE "{column}"{cast}
END AS "{column}"
"""
)
select = [f'"{column}"' for column in unsorted_columns]
select = ", ".join(select)

# Fetch the rows from the table and write them to a corresponding TSV file in the
# output directory:
cursor.execute(f'SELECT {select} FROM "{table}_view" ORDER BY "row_number"')
cursor.execute(f'SELECT {select} FROM "{table}_text_view" ORDER BY "row_number"')
colnames = [d[0] for d in cursor.description]
rows = map(lambda r: dict(zip(colnames, r)), cursor)
fieldnames = [c for c in colnames if c != "row_number"]
Expand Down
Loading

0 comments on commit f4d1528

Please sign in to comment.