Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-08-01 Thread Simon King
It's a horrible hack, but did you know that you can change the class of an instance by assigning to its __class__ attribute? I've no idea if SA does anything that would stop this from working, but you could try it. Start by creating a subclass of Table with your extra methods, then iterate over

Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-08-01 Thread askel
No offence but it feels like direct route to the hell. Monkeypatching is acknowledged to be really bad practise in general with few exemptions. On Thursday, August 1, 2013 9:47:45 AM UTC-4, Simon King wrote: It's a horrible hack, but did you know that you can change the class of an instance

Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-08-01 Thread Michael Bayer
as I mentioned earlier, SQLAlchemy-Migrate has done it this way for years. I'm not a fan of it which was one of several reasons I wrote Alembic, but it does work for them. On Aug 1, 2013, at 10:21 AM, askel dummy...@mail.ru wrote: No offence but it feels like direct route to the hell.

Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-08-01 Thread Gustavo Baratto
I did this to quickly test my own extended ResultProxy object, but as soon figured out how easy was to properly instantiate a new ResultProxy subclass from an existing ResultProxy object, I got rid of this monkeypatching. I'd like to avoid that route if possible. Thanks! :) g. On Thu, Aug 1,

[sqlalchemy] Extending sqlalchemy.schema.Table

2013-07-31 Thread tiadobatima
Hello there, When this application starts, we reflect the DB into a MetaData() object and this is made available for everyone to use. I'd like to add a few more methods to the table objects within that MetaData(). Is there any easy way to extend these already instantiated

Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-07-31 Thread Michael Bayer
You'd probably implement your own reflect_all function/method: from sqlalchemy import inspect def reflect(metadata, bind): inspector = inspect(bind) for tname in inspector.get_table_names(): MySpecialTable(tname, metadata, autoload=True, autoload_with=bind) On Jul 31, 2013, at

Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-07-31 Thread Michael Bayer
oh, except you might have problems with tables in there that are reflected due to a foreign key.Table is not really intended for subclassing, unless you want to do SQLAlchemy-Migrate's approach of monkeypatching Table.__bases__ at the global level, I'd seek some other way to achieve what

Re: [sqlalchemy] Extending sqlalchemy.schema.Table

2013-07-31 Thread Gustavo Baratto
Thanks for the reply Michael... I had a hunch this wouldn't be easy to tackle, but this is more than I can chew at the moment: ) For now, I'll just keeping doing what I'm already doing which is to instantiate a new class taking the table as an argument, and then within my class reference the