Skip to content

Commit

Permalink
allow SQL header comments at top of files
Browse files Browse the repository at this point in the history
  • Loading branch information
nackjicholson committed Sep 27, 2020
1 parent ee3e589 commit 9c3cc26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions aiosql/query_loader.py
Expand Up @@ -73,9 +73,13 @@ def _make_query_datum(self, query_str: str):

def load_query_data_from_sql(self, sql: str) -> List[QueryDatum]:
query_data = []
for query_sql_str in query_name_definition_pattern.split(sql):
if not empty_pattern.match(query_sql_str):
query_data.append(self._make_query_datum(query_sql_str))
query_sql_strs = query_name_definition_pattern.split(sql)

# Drop the first item in the split. It is anything above the first query definition.
# This may be SQL comments or empty lines.
# See: https://github.com/nackjicholson/aiosql/issues/35
for query_sql_str in query_sql_strs[1:]:
query_data.append(self._make_query_datum(query_sql_str))
return query_data

def load_query_data_from_file(self, file_path: Path) -> List[QueryDatum]:
Expand Down
3 changes: 3 additions & 0 deletions tests/blogdb/sql/users/users.sql
@@ -1,3 +1,6 @@
-- SQL COMMENT THAT SHOULD BE ALLOWED
-- WAS BREAKING IN THIS ISSUE https://github.com/nackjicholson/aiosql/issues/35

-- name: get-all
-- Get all user records
select * from users;
Expand Down

0 comments on commit 9c3cc26

Please sign in to comment.