Re: [SQLObject] More connections for more tables
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Juan M. S. <vic...@gm...> - 2010-04-13 22:24:45
|
From: Visgean Skeloru <vi...@gm...> To: sql...@li... Date: Tuesday 13 April 2010 > Hello is it possible to set a specific connections database for each class? > > because i have 2 class and one of them is temporary so i would like to use > sqlite in memory. Yes, it's possible. One way is to pass a connection parameter at class creation (that's at least the way I do it). This may look like: from sqlobject import SQLObject, connectionForURI class AnObject(SQLObject): one_attr = StringCol() con = connectionForURI("sqlite:/:memory:") obj = AnObject(one_attr="one attr", connection=con) The other way is defining the _connection attribute on the class definition. I have never tried it but from reading the doc I think I remember it quite like this: con = connectionForURI("sqlite:/:memory:") class AnObject(SQLObject) one_attr = StringCol() _connection = con With the first one you have to keep in mind to pass the connection parameters in later operations, such as select (again, that's at least the way I do it). I have never fiddled with the second one, so I can't provide some experience on the matter. Please do post your results :) Cheers Juan Manuel Santos |