Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added argparse factory, working skip table #40

Closed
wants to merge 1 commit into from

Conversation

emattiza
Copy link

To make better, perhaps there is a way to not re-reflect?

Implementation performs two tasks:

  • factory for arg parse parser
  • logic to handle skipped tables
    • Currently runs on tables spec'ed or grabs all,
    • diffs skiptable args if specified from tables found
    • re-reflects schema from tables list less the skipped_tables

Apologies for the wrong pull request earlier. This will be on the 1.1 branch exclusively.

Ref: Issue #39

To make better, perhaps there is a way to not re-reflect?
@emattiza
Copy link
Author

def _filter_tables_list(table_name, metadata_obj):
    '''
    A callable function passed to MetaData.reflect which returns boolean predicates on args entered
    First, return False for all tables in skiptables
    Second, if tables arg is non-empty, only return tables specified; Else return all tables
    :param table_name: string
    :param metadata_obj: sqlalchemy.MetaData
    :return: bool
    '''
    if table_name in args.skiptables:
        return False
    if args.tables:
        if table_name in args.tables:
            return True
        else:
            return False
    else:
        return True

This uses the sqlalchemy metadata.reflect(only=) in a callable which should prevent re-reflection and is a bit cleaner. I have this in a separate branch but will merge into my 1.1 and this pull request if you feel this is a better choice.

@agronholm
Copy link
Owner

I don't quite understand the point here.

@agronholm
Copy link
Owner

If your intent was on adding a "skip-tables" feature, I'm not inclined to merge something like that because it runs contrary to the intended workflow of sqlacodegen. If you want to skip some tables, why not just delete them from the generated code? Moreover, this PR touches a lot more than just one extra option and that is a no-no.

@agronholm agronholm closed this May 19, 2018
@gmonkman
Copy link

Because sqlcodeagen does not support all data types, for example, there is no support for the MSSQL spatial data types. Being able to exclude tables which contain unsupported data type would be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants