Skip to content

Commit ad71f00

Browse files
author
Rohit Shende
committed
Changes Done:
1. Changed version to 1.1.8 2. Added support for --notables (if we only want classes for all models and not tables) 3. Fixed a bug for ENUM renamed to db.Enum 4. Added check to not add the model imports when --flask is supplied 5. Added requirements.txt for the developers to contribute
1 parent 0687f1c commit ad71f00

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

requirements.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apipkg==1.5
2+
atomicwrites==1.4.0
3+
attrs==19.3.0
4+
colorama==0.4.3
5+
execnet==1.7.1
6+
importlib-metadata==1.6.0
7+
inflect==4.1.0
8+
more-itertools==8.2.0
9+
packaging==20.3
10+
pep8==1.7.1
11+
pluggy==0.13.1
12+
py==1.8.1
13+
PyMySQL==0.9.3
14+
pyparsing==2.4.7
15+
pytest==5.4.2
16+
pytest-cache==1.0
17+
pytest-pep8==1.0.6
18+
six==1.14.0
19+
SQLAlchemy==1.3.17
20+
wcwidth==0.1.9
21+
zipp==3.1.0

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def run_tests(self):
4242
'Programming Language :: Python :: 3.2',
4343
'Programming Language :: Python :: 3.3',
4444
'Programming Language :: Python :: 3.4',
45-
'Programming Language :: Python :: 3.5'
45+
'Programming Language :: Python :: 3.5',
46+
'Programming Language :: Python :: 3.6',
47+
'Programming Language :: Python :: 3.7'
4648
],
4749
keywords=['sqlalchemy', 'sqlacodegen', 'flask'],
4850
license='MIT',

sqlacodegen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = __version__ = '1.1.7'
1+
version = __version__ = '1.1.8'

sqlacodegen/codegen.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ def _render_column_type(coltype):
126126
else:
127127
args.append(repr(value))
128128

129-
text = _flask_prepend + coltype.__class__.__name__
129+
# In case of ENUM from sqlalchemy.dialects, the flask used db.Enum
130+
if coltype.__class__.__name__ == "ENUM":
131+
text = _flask_prepend + "Enum"
132+
else:
133+
text = _flask_prepend + coltype.__class__.__name__
134+
130135
if args:
131136
text += '({0})'.format(', '.join(args))
132137

@@ -529,7 +534,7 @@ class CodeGenerator(object):
529534

530535
def __init__(self, metadata, noindexes=False, noconstraints=False,
531536
nojoined=False, noinflect=False, nobackrefs=False,
532-
flask=False, ignore_cols=None, noclasses=False, nocomments=False):
537+
flask=False, ignore_cols=None, noclasses=False, nocomments=False, notables=False):
533538
super(CodeGenerator, self).__init__()
534539

535540
if noinflect:
@@ -603,15 +608,22 @@ def __init__(self, metadata, noindexes=False, noconstraints=False,
603608
table.c[colname].type = Enum(*options, native_enum=False)
604609
continue
605610

606-
# Only form model classes for tables that have a primary key and are not association tables
607-
if not table.primary_key or table.name in association_tables or noclasses:
611+
# Only generate classes when notables is set to True
612+
if notables:
613+
model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
614+
classes[model.name] = model
615+
elif not table.primary_key or table.name in association_tables or noclasses:
616+
# Only form model classes for tables that have a primary key and are not association tables
608617
model = ModelTable(table)
609618
elif not noclasses:
610619
model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
611620
classes[model.name] = model
612621

613622
self.models.append(model)
614-
model.add_imports(self.collector)
623+
624+
# collect imports for models only if flask is not specified
625+
if not self.flask:
626+
model.add_imports(self.collector)
615627

616628
# Nest inherited classes in their superclasses to ensure proper ordering
617629
for model in classes.values():

sqlacodegen/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def main():
3333
parser.add_argument('--nojoined', action='store_true', help="don't autodetect joined table inheritance")
3434
parser.add_argument('--noinflect', action='store_true', help="don't try to convert tables names to singular form")
3535
parser.add_argument('--noclasses', action='store_true', help="don't generate classes, only tables")
36+
parser.add_argument('--notables', action='store_true', help="don't generate tables, only classes")
3637
parser.add_argument('--outfile', help='file to write output to (default: stdout)')
3738
parser.add_argument('--nobackrefs', action='store_true', help="don't include backrefs")
3839
parser.add_argument('--flask', action='store_true', help="use Flask-SQLAlchemy columns")
@@ -57,7 +58,7 @@ def main():
5758
outfile = codecs.open(args.outfile, 'w', encoding='utf-8') if args.outfile else sys.stdout
5859
generator = CodeGenerator(metadata, args.noindexes, args.noconstraints,
5960
args.nojoined, args.noinflect, args.nobackrefs,
60-
args.flask, ignore_cols, args.noclasses, args.nocomments)
61+
args.flask, ignore_cols, args.noclasses, args.nocomments, args.notables)
6162
generator.render(outfile)
6263

6364

0 commit comments

Comments
 (0)