On Monday 23 March 2009 23:51:26 Christiaan Putter wrote: > Hi, > > You're quite right, the join was the tricky bit at first. >....... > > The 'dynamically' added classes look something like this: > > class SMAFields(SecurityFields): > > sma10 = Float(sqldb=True) > > def _get_sma10(self): > ## some algo ### > return res > > > That code just resides in some text editor provided for the user > where he can change it, add new class etc. Then from within the > main app I use exec to compile it. The base class sets up the > mapping, foreign keys, creates the table and also adds the sma10 > column to the Security class. Which is why I can then: > > data = q.filter(Security.sma10 >= 5)[:] > > So even though the sma10 column isn't on the Security table itself, > through the foreign key constraint and the outer join, it behaves > as one would expect. > > And the query only returns Security instances because I use > sess.query(Security), without any of the other added classes. > > That all works quite well. The problems I'm having right now: > > 1. figuring out what the best practice is for working with data > using multiple threads > -> only have one session in the gui thread? other threads call > commit on this session using a lock? > -> expunge instances from gui sess before working on then, then > commit changes in new session? then add them back to gui's > session? > > 2. Creation of SMAFields records if they don't exist. Right now > I'm just creating them by hand. Though automatic creation when > loading a Security would be nice. > -> tried with orm.reconstruct decorator on Security class, > doesn't seem to work.
can't really help u here... for multithread, try whichever is easier to make _now_, and think about redoing it for real later... why multithread though? reconstruct is when loading from db to memory. IMO u need "on_save"-like thing - see mapper extensions / session extensions. > Maybe a bit too complicated for what it achieves, but the ability > to define new fields with custom algorithms on the fly can be quite > useful for users. the "dynamic ORM" road is not really travelled too much... keep going. maybe put what u did somewhere to be visible? with _good_ description what u need from it... ciao svil --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---