The example works wonderfully, however i noticed, that when i attach a constraint to the column, it gets mirrored in the table
so the event handler @event.listens_for(PString, "after_parent_attach") def create_constraint(target, parent): @event.listens_for(parent, "after_parent_attach") def add_to_table(col, table): col.constraints.add(CheckConstraint(parent != '')) will result in CREATE TABLE fun ( name VARCHAR(100) CHECK (name != ''), CHECK (name != '') ) instead of CREATE TABLE fun ( name VARCHAR(100) CHECK (name != '') ) when using m = MetaData() t = Table( 'fun', m, Column('name', PString(100)), ) e = create_engine('sqlite://', echo=1) m.create_all(e) m.drop_all(e) assert 0 On Wednesday, December 18, 2013 5:26:53 PM UTC+1, Michael Bayer wrote: > > > On Dec 18, 2013, at 5:41 AM, RonnyPfannschmidt > <ronny.pfa...@gmail.com<javascript:>> > wrote: > > > Hi, > > > > for supporting a certain schema requirement, > > i have to create a quite a number of columns that are checked not to be > a empty string, > > > > So i'd like to declare a custom type, which will automatically imply the > check on those columns. > > > > I already Investigated, how Boolean does this for databases with > non-native boolean types, > > however it uses number "private" methods, > > > > Should i follow its example or is there a official way? > > > > what i currently have to do is > > > > Column('foo', String(20), CheckConstraint("foo <> ''") > > > > what i'd like use is something like > > > > Column('foo', PString(20)) > > you’d use a TypeDecorator for this. See the example > http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#coercing-encoded-strings-to-unicodefor > something similar (coerces to utf-8, just replace that with checking > for non-empty). > > > -- 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 http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.