On Thu, Sep 14, 2017 at 11:35 PM, Philip Martin <philip.martin2...@gmail.com> wrote: > Mike, thanks for the prompt response and all of your work on the library. > Looking over the generic_repr again it now looks more general. While not > according for positional arguments, probably something like what I have > below seems to work. I'm guessing by design we should expect the parameter > order to follow the convention of the SQL/dialect specific order if it's in > the library?
I don't think I understand the question. There's a "convention" that the datatypes will have an attribute named after the constructor argument, (e.g. type(length=5) will give you type.length), if that's what you mean. > > def get_type_attributes(data_type): > """Get SQL data type attributes.""" > > from inspect import signature > > sig = signature(data_type.__init__) > > output = [] > > for attribute, parameter in sig.parameters.items(): > if parameter.kind is parameter.POSITIONAL_OR_KEYWORD: > value = getattr(data_type, attribute) > > if parameter.default is sig.empty: > output.append(value) > elif parameter.default != value: > output.append((attribute, value)) > > return output > > > > > On Thursday, September 14, 2017 at 2:37:03 PM UTC-5, Mike Bayer wrote: >> >> On Thu, Sep 14, 2017 at 10:49 AM, Philip Martin >> <philip.m...@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+...@googlegroups.com. >> > To post to this group, send email to sqlal...@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. -- 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.