Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotosm/osm-rawdata
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Feb 8, 2024
2 parents bef7cf3 + 40f121e commit 97419fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion osm_rawdata/pgasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def connect(
self.url = os.getenv("UNDERPASS_API_URL", "https://raw-data-api0.hotosm.org/v1")
self.headers = {"accept": "application/json", "Content-Type": "application/json"}
else:
log.debug(f"Connecting with: {connect}")
# log.debug(f"Connecting with: {connect}")
try:
self.pg = await asyncpg.connect(connect)
if self.pg.is_closed():
Expand Down Expand Up @@ -305,6 +305,7 @@ async def execute(
Returns:
(list): The results of the query
"""

# print(sql)
try:
result = await self.pg.fetch(sql)
Expand Down
24 changes: 22 additions & 2 deletions osm_rawdata/postgres.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

# Copyright (c) 2022 Humanitarian OpenStreetMap Team
# Copyright (c) 2022, 2023, 2024 Humanitarian OpenStreetMap Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -380,6 +380,26 @@ def createTable(

return True

def execute(self,
sql: str,
):
"""
Execute a raw SQL query and return the results.
Args:
sql (str): The SQL to execute
Returns:
(list): The results of the query
"""
# print(sql)
try:
result = self.dbcursor.execute(sql)
return self.dbcursor.fetchall()
except:
log.error(f"Couldn't execute query! {sql}")
return list()

def queryLocal(
self,
query: str,
Expand Down Expand Up @@ -421,7 +441,7 @@ def queryLocal(
self.dbcursor.execute(query)
try:
result = self.dbcursor.fetchall()
log.debug("SQL Query returned %d records" % len(result))
# log.debug("SQL Query returned %d records" % len(result))
except:
return FeatureCollection(features)

Expand Down

0 comments on commit 97419fb

Please sign in to comment.