Add support for database views, fixes #235, fixes #267.

This commit is contained in:
Friedrich Lindenberg 2020-01-11 16:46:04 +01:00
parent fc3af9e1f1
commit 354a51bf98
2 changed files with 12 additions and 2 deletions

View File

@ -145,10 +145,20 @@ class Database(object):
"""Get a listing of all tables that exist in the database."""
return self.inspect.get_table_names(schema=self.schema)
@property
def views(self):
"""Get a listing of all views that exist in the database."""
return self.inspect.get_view_names(schema=self.schema)
def __contains__(self, table_name):
"""Check if the given table name exists in the database."""
try:
return normalize_table_name(table_name) in self.tables
table_name = normalize_table_name(table_name)
if table_name in self.tables:
return True
if table_name in self.views:
return True
return False
except ValueError:
return False

View File

@ -288,7 +288,7 @@ class Table(object):
schema=self.db.schema,
autoload=True)
except NoSuchTableError:
pass
self._table = None
def _threading_warn(self):
if self.db.in_transaction and threading.active_count() > 1: