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 table's attributes most likely to be used (See below).
If there is a more elegant way of doing this, I'm all ears ;)

Thanks!

Class MyGenericTable(object):
    def __init__(self, table):
        self.tablename = table

    @property
    def metadata(self):
        return DB.instance().metadata

    @property
    def table(self):
        return self.metadata.tables[self.tablename]

   @property
   def columns(self):
       return self.table.c

   @property

  def c(self):
      return self.columns

@property
def *primary_key*(self):
    return self.table.primary_key


   def select(self, data):
       """ my select """
       some custom code

   def insert(self, data):
       """ my insert """
       some custom code




On Wed, Jul 31, 2013 at 10:57 AM, Michael Bayer <mike...@zzzcomputing.com>wrote:

> 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 you want.
>
>
>
> On Jul 31, 2013, at 1:56 PM, Michael Bayer <mike...@zzzcomputing.com>
> wrote:
>
> 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 1:34 PM, tiadobatima <gbara...@gmail.com> wrote:
>
> 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 sqlalchemy.schema.Table objects?
>
> Thanks! :)
>
>
> --
> 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.
>
>
>
>
>
>

-- 
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.


Reply via email to