On Thu, Sep 14, 2017 at 10:49 AM, Philip Martin
<philip.martin2...@gmail.com> wrote:
> We have several third-party vendors that provide us with large, normalized
> schema (100+) tables. I am looking to quickly discover probable foreign keys
> based on a column's name and data type attributes.
>
> For the data type attributes, I am looking to extract any attribute values
> set on the data type object. For instance:
>
> import sqlalchemy as sa
>
> char = sa.CHAR(2)
>
> print(char.__dict__)
>
>
>
>>>> {'unicode_error': None, 'collation': None, 'convert_unicode': False,
>>>> '_warn_on_bytestring': False, 'length': 2}
>
> In this instance, I want to programmatically separate the length attribute
> as an actual database type attribute from convert_unicode.

you might not want to ignore collation if you are on MySQL, as this
can impact whether or not a foreign key can be created.

>
> Digging through the code base the best example I could find for this
> behavior is in util.generic_repr where a similar function could output an
> ordered dict versus a formatted string.
> Is there a more direct way/existing
> function in Sqlalchemy to accomplish this or something that could be useful
> to add to the library? If not, can I have permission to reference and modify
> the existing code in util.generic_repr?

you can make use of util.generic_repr() but as far as generalizing
that function for public consumption it's kind of something that
should be on pypi by itself.   It would need many more tests, support
for programming patterns like varargs and py3k required positional
arguments, none of which SQLAlchemy needs right now.



>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to