On Wednesday, January 13, 2016 at 10:54:04 AM UTC-5, Michael Bayer wrote: > > > > On 01/13/2016 12:37 AM, Jonathan Rogers wrote: > > I have several domains based on type TEXT to constrain values in > > specific ways, such as to disallow empty values or only allow valid > > email addresses. When I reflect tables with columns of such a domain, > > SQLAlchemy simply considers their types to be TEXT. Is there any way to > > make the domains known to SQLAlchemy so that it can treat them as > > distinct types? My goal is to define a new table with nearly identical > > structure to an existing one, adding some columns in the process. I > > looked over > > > > > > "Custom Types" in the manual but I wasn't sure where to start. Would I > > be creating an entirely new type or augmenting an existing one? > > This is a Text subtype so I'd have TEXT in the superclass, the @compiles > approach can be used to give it its DDL: > > from sqlalchemy.types import TEXT > from sqlalchemy.ext.compiler import compiles > > class MyType(TEXT): > pass > > @compiles(MyType) > def _mytype(elem, compiler, **kw): > return "MYTYPE" > > Thanks. That was just the hint I needed. Initially, I was hoping that I could get SQLAlchemy to reflect the domains but I ended up using explicit declarations anyway.
-- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
