Skip to content

Commit

Permalink
prep for extending Database
Browse files Browse the repository at this point in the history
  • Loading branch information
fpurcell committed Mar 10, 2018
1 parent 0236651 commit 3ea994b
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions gtfsdb/model/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,34 @@ def __init__(self, **kwargs):

@property
def classes(self):
from gtfsdb.model.base import Base
subclasses = self.get_base_subclasses()
if self.tables:
return [c for c in Base.__subclasses__() if c.__tablename__ in self.tables]
ret_val = [c for c in subclasses if c.__tablename__ in self.tables]
else:
ret_val = subclasses
return ret_val

@classmethod
def get_base_subclasses(cls):
from gtfsdb.model.base import Base
return Base.__subclasses__()

@property
def metadata(self):
from gtfsdb.model.base import Base
return Base.metadata

@classmethod
def factory_from_cmdline(cls, args):
kwargs = dict(
tables=args.tables,
url=args.database_url,
schema=args.schema,
is_geospatial=args.is_geospatial
)
ret_val = Database(kwargs)
return ret_val

def create(self):
"""Drop/create GTFS database"""
for cls in self.sorted_classes:
Expand All @@ -43,11 +66,6 @@ def create(self):
def dialect_name(self):
return self.engine.url.get_dialect().name

@property
def metadata(self):
from gtfsdb.model.base import Base
return Base.metadata

@property
def is_geospatial(self):
return self._is_geospatial
Expand Down Expand Up @@ -75,6 +93,8 @@ def schema(self):
def schema(self, val):
# import pdb; pdb.set_trace()
self._schema = val

# TODO ... move to create() method
try:
if self._schema:
from sqlalchemy.schema import CreateSchema
Expand Down

0 comments on commit 3ea994b

Please sign in to comment.