Skip to content

Commit

Permalink
Add support for '#' and '-- ' comments in sql files
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWillitts committed Jun 21, 2024
1 parent 53226ea commit 02b4744
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions edc_qareports/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def read_unmanaged_model_sql(
) -> str:
if not fullpath:
fullpath = Path(settings.BASE_DIR) / app_name / "models" / "unmanaged" / filename

parsed_sql = []
with fullpath.open("r") as f:
sql = f.read()
return sql.replace("\n", " ")
for line in f:
line = line.split("#", maxsplit=1)[0]
line = line.split("-- ", maxsplit=1)[0]
line = line.replace("\n", "")
line = line.strip()
if line:
parsed_sql.append(line)

return " ".join(parsed_sql)

0 comments on commit 02b4744

Please sign in to comment.