Skip to content

Commit

Permalink
fix:dev:Get catalog query through overridden method
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Venkatesh authored and vrajat committed Mar 29, 2019
1 parent 9614bb5 commit 8fc1261
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions piicatcher/dbexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ def get_columns(self, schema_name, table_name):
return columns


class CachedExplorer(Explorer):
class CachedExplorer(Explorer, ABC):

def __init__(self):
super(CachedExplorer, self).__init__("")
self._cache_ts = None

@abstractmethod
def _get_catalog_query(self):
pass

def _load_catalog(self):
if self._cache_ts is None or self._cache_ts < datetime.now() - timedelta(minutes=10):
with self.get_connection().cursor() as cursor:
cursor.execute(self._catalog_query)
cursor.execute(self._get_catalog_query())
self._schemas = []

row = cursor.fetchone()
Expand Down Expand Up @@ -224,6 +228,9 @@ def _open_connection(self):
user=self.user,
password=self.password)

def _get_catalog_query(self):
return self._catalog_query


class PostgreSQLExplorer(CachedExplorer):
_catalog_query = """
Expand All @@ -247,3 +254,5 @@ def _open_connection(self):
password=self.password,
database=self.database)

def _get_catalog_query(self):
return self._catalog_query

0 comments on commit 8fc1261

Please sign in to comment.