if you dont have a session to work with then youd just use  
connections off the engine being used.

if you have your engines bound to tables and you want to get at that  
via the mapped class, first off id say why not just have the engine  
by itself somewhere?  but if you really need to, it looks like

        class_mapper(someclass).mapped_table.metadata.engine

for some examples about how to mix connections/sessions/transactions,  
see

http://www.sqlalchemy.org/docs/unitofwork.myt#unitofwork_transaction
http://www.sqlalchemy.org/docs/unitofwork.myt#unitofwork_transaction_sql
http://www.sqlalchemy.org/docs/ 
unitofwork.myt#unitofwork_transaction_using


On Jul 13, 2006, at 2:03 PM, Randall Smith wrote:

> What if I don't have access to session?  I receive obj (mapped SQLA
> class instance) as an argument to a method.
>
> What I actually would like to do is add a method to the class that  
> does
> the raw query like so:
>
> class MyClass(object):
>      def __init__(self, arg1, arg2):
>          self.arg1 = arg1
>          self.arg2 = arg2
>
>      @property
>      def fetchOutsideAtts(self):
>          con = getConnection(self) # How do I do this.
>          con.execute(select fields from table where id = ?)
>          ...
>          return atts
>
> Is it possible to do this?
>
> Randall
>
> Michael Bayer wrote:
>> the connection is returned relative to the mapper given, since there
>> can be more than one engine in use:
>>
>>      conn = session.connection(<mapper>)
>>
>> although if the Session is bound to an engine which you want to use,
>> which is probably what you want, then you can just say:
>>
>>      conn = session.connection(None)
>>
>> I may make the argument optional soon, so it would just be
>> session.connection().
>>
>> then with the connection you can just execute things:
>>
>>      result = conn.execute(sometable.select(), **params)
>
>
>
> ---------------------------------------------------------------------- 
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to