[sqlalchemy] Re: adding objects to table only once

2008-11-19 Thread rca
I second Eric's opinion, the EntitySingleton is an useful recipy and I used it in SQLAlchemy 5. I think it can be used in your situation well On Nov 18, 6:51 pm, Eric Ongerth [EMAIL PROTECTED] wrote: Faheem, On a closely related note, you may find the following 'usage recipe' interesting,

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Michael Bayer
a guaranteed stable way that doesn't rely on SQLAlchemy implementation details and is easy to understand is here. this is how I would do it: http://pastebin.com/f6670eebe Joril wrote: Hi everyone! I'm still working on implementing data logging with SQLAlchemy (=whenever someone updates a

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Joril
On 19 Nov, 16:28, Michael Bayer [EMAIL PROTECTED] wrote: a guaranteed stable way that doesn't rely on SQLAlchemy implementation details and is easy to understand is here.  this is how I would do it: http://pastebin.com/f6670eebe I see, many thanks for yor time :) Out of curiosity, is there a

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Michael Bayer
Joril wrote: On 19 Nov, 16:28, Michael Bayer [EMAIL PROTECTED] wrote: a guaranteed stable way that doesn't rely on SQLAlchemy implementation details and is easy to understand is here.  this is how I would do it: http://pastebin.com/f6670eebe I see, many thanks for yor time :) Out of

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Joril
On 19 Nov, 17:22, Michael Bayer [EMAIL PROTECTED] wrote: Out of curiosity, is there a solution that wouldn't require creating new instances of the objects? (Some magic incantation like the del instance_state(entity).key you suggested me some time ago, I guess..?) not really since you'd

[sqlalchemy] Re: Data logging and many-to-many's

2008-11-19 Thread Michael Bayer
Joril wrote: I see.. But - sorry if I insist - are you implying that it would be too difficult to do? I know it'd be a kind of ugly hack, but since I spent almost the whole day looking for it, now I'm wondering if I was looking for something that doesn't exist at all X-) you'd need to use a

[sqlalchemy] ORM Query that selects only a subset of the columns

2008-11-19 Thread Moshe C.
For Query there is an add_column() method, but I do not see a remove column method. Initializing a Query requires a full mapped class, so how can I select on only a subset of the columns. I want to do this for ding a DISTINCT query on only a couple of columns. TIA Moshe

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Moshe C.
0.4.6 On Nov 19, 11:12 pm, Bobby Impollonia [EMAIL PROTECTED] wrote: What version of SQLA are you using? In .5 , you can pass individual columns instead of a mapped class to session.query. On Wed, Nov 19, 2008 at 12:17 PM, Moshe C. [EMAIL PROTECTED] wrote: For Query there is an

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Bobby Impollonia
Yeah, with .4 there isn't really a way have an ORM query that doesn't select at least one ORM object (possibly with additional columns/ objects added via add_column/ add_entity). You can use the select() construct instead if pulling all the columns of the mapped class is unacceptable. On Wed,

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Michael Bayer
0.4.7 and above supports query.values(col1, col2, ...) . use that. Bobby Impollonia wrote: Yeah, with .4 there isn't really a way have an ORM query that doesn't select at least one ORM object (possibly with additional columns/ objects added via add_column/ add_entity). You can use the

[sqlalchemy] Re: JOIN to subquery in mapper

2008-11-19 Thread indigophone
I gave it a shot but I am no closer to knowing how to do this. On Nov 19, 12:00 am, Michael Bayer [EMAIL PROTECTED] wrote: joining to a subquery is better accomplished outside of relation()   using query, such as query(USZipCode).join((subquery,   subquery.c.col==USZipCode.somecol)). Now

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Michael Bayer
query.distinct().values() or query.values(func.distinct(func.count(table.c.column))) Moshe C. wrote: How would that work with distinct() ? I see it returns an iterator and not a Query. On Nov 19, 11:39 pm, Michael Bayer [EMAIL PROTECTED] wrote: 0.4.7 and above supports query.values(col1,

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Michael Bayer
if 0.4.6 works you're great. take a look at the changelog to see what bugs have been fixed between 0.4.6 and 0.4.8. Moshe C. wrote: I have tried it out on 0.4.6 and it is working nicely. You mentioned 0.4.7 . Is there any bug I should be aware of in 0.4.6? I cannot upgrade in the near

[sqlalchemy] Re: JOIN to subquery in mapper

2008-11-19 Thread Michael Bayer
its impossible to know what you want without seeing literal SQL but this is the general idea from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class USCity(Base): __tablename__ = 'cities' id =

[sqlalchemy] Re: ORM Query that selects only a subset of the columns

2008-11-19 Thread Moshe C.
Apparently, nothing changed specifically with the values() functionality. It was added as _values() in 0.4.5 . I guess 0.4.6 was the release of this feature, then. Cool. Thanks for your help On Nov 20, 12:47 am, Michael Bayer [EMAIL PROTECTED] wrote: if 0.4.6 works you're great.  take a

[sqlalchemy] Re: Using SQLAlchemy with multiple classes/modules

2008-11-19 Thread Power Button
hi there, thanks for this. Has cleared alot of things up. thanks again for the nice library. On Nov 17, 3:34 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Nov 17, 2008, at 7:17 AM, Power Button wrote: What I have tried is putting all the setup instructions into a class and