[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread Chris Withers
a...@svilendobrev.com wrote: use the relation as a join path, and then whatever filtering/ordering try: unit.join(Unit.records).order_by(Record.date.desc()).first() or unit.join('records').order_by(Record.date.desc()).first() That gives me: AttributeError: 'Unit' object has no

[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread az
ah, it has to be other way around unit = session.query(Unit).filter(Unit.id==3).first() rec = sess.query( Record).filter( Record.theunit == unit)... where theuint is the backref of Unit.records. see http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-relation-operators or just wait for

[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread Chris Withers
a...@svilendobrev.com wrote: rec = sess.query( Record).filter( Record.theunit == unit)... Is this as nice as I can get it or is their a slicker solution? or just wait for Mike (-:) Hopefully Mr Bayer can enlighten me :-) Chris -- Simplistix - Content Management, Zope Python Consulting

[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread az
On Friday 13 February 2009 11:02:13 Chris Withers wrote: a...@svilendobrev.com wrote: rec = sess.query( Record).filter( Record.theunit == unit)... Is this as nice as I can get it or is their a slicker solution? this might work too rec = sess.query( Record).filter_by( theunit = unit)...

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread az
On Friday 13 February 2009 11:07:29 koranthala wrote: Hi, I am working on a Python application which does approximately 1000 updates at a time every 3 seconds in a Sqlite File Database using SqlAlchemy. On timing it in a 2GHz machine, I found that it is taking ~1.01 seconds to do the

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread koranthala
On Feb 13, 2:11 pm, a...@svilendobrev.com wrote: On Friday 13 February 2009 11:07:29 koranthala wrote: Hi,     I am working on a Python application which does approximately 1000 updates  at a time every 3 seconds in a Sqlite File Database using SqlAlchemy. On timing it in a 2GHz

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread az
The inserts I do is as follows: BEGIN: 2009-02-13 14:34:40,703 INFO sqlalchemy.engine.base.Engine.0x..10 UPDATE data SET status=? WHERE data.index = ? 2009-02-13 14:34:40,703 INFO sqlalchemy.engine.base.Engine.0x..10 ['True', 68762] ... (1000) ... COMMIT

[sqlalchemy] Re: sqlsoup + with_labels not working on one table?

2009-02-13 Thread Stuart Axon
Some more testing... - Note, I'm just trying to get the joins working before using the queries with session etc m = db.devmap_manufacturer d = db.devmap_device d.join(m).first() MappedDevmap_device(id=1,device_name='otc701',manufacturer_id=1) m = db.with_labels(db.devmap_manufacturer) d

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread MikeCo
Using an update query with synchronize_session=False will generate a single SQL statement that will be as efficient as possible. Look at this example http://stackoverflow.com/questions/270879/efficiently-updating-database-using-sqlalchemy-orm/270942 and docs

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread Michael Trier
Hi, On Fri, Feb 13, 2009 at 7:26 AM, MikeCo mconl...@gmail.com wrote: The ORM will probably have a little bit of function call overhead compared to the SQL Expression Language, and that may no longer be the case. Regardless with the ORM you're going to want to use the update method as stated by

[sqlalchemy] logger configuration for sqlalchemy

2009-02-13 Thread przemek.ch
Hi, Using sql alchemy with pylons I get warnings like this: C:\Python26\lib\site-packages\sqlalchemy-0.5.3dev-py2.6.egg\sqlalchemy \orm\scoping.py:121: SADeprec ationWarning: Use session.add() return getattr(self.registry(), name)(*args, **kwargs) I know that its caused by deprecation of

[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread Michael Bayer
On Feb 12, 2009, at 6:42 PM, Chris Withers wrote: Hi All, With the model from my previous post, I'm looking to find the latest Record for a particular Unit. Someone on #sqlalchemy suggested this: unit = session.query(Unit).filter(Unit.id==3).first() record =

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread Michael Bayer
On Feb 13, 2009, at 4:07 AM, koranthala wrote: Hi, I am working on a Python application which does approximately 1000 updates at a time every 3 seconds in a Sqlite File Database using SqlAlchemy. On timing it in a 2GHz machine, I found that it is taking ~1.01 seconds to do the same.

[sqlalchemy] Re: logger configuration for sqlalchemy

2009-02-13 Thread Michael Bayer
use the warnings filter described in the Python library documentation to configure the behavior of warnings. On Feb 13, 2009, at 4:42 AM, przemek.ch wrote: Hi, Using sql alchemy with pylons I get warnings like this: C:\Python26\lib\site-packages\sqlalchemy-0.5.3dev-py2.6.egg\sqlalchemy

[sqlalchemy] Re: Problem with inheritance and cross relations (was: Unable to model cross relations (using ext.declarative))

2009-02-13 Thread Michael Bayer
which two tables are concrete ? I dont see the concrete=True keyword used in your mapping setup, but then again I don't see the inherits keyword either, so the usage of polymorphic_identity/ polymorphic_on is useless here. you'd just configure Node and Product mappers completely

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread Michael Bayer
On Feb 13, 2009, at 10:08 AM, Michael Bayer wrote: On Feb 13, 2009, at 4:07 AM, koranthala wrote: Hi, I am working on a Python application which does approximately 1000 updates at a time every 3 seconds in a Sqlite File Database using SqlAlchemy. On timing it in a 2GHz machine, I

[sqlalchemy] text binding for sql queries

2009-02-13 Thread Max Ischenko
I get an error when I'm trying tu run this: stmt = text(select * from salary_data_new where codeword=:codeword union select * from salary_data_clean where codeword=:codeword ) # s is instance of Session() class factory

[sqlalchemy] Re: text binding for sql queries

2009-02-13 Thread az
i guess s.execute(stmt, params=dict(codeword=codeword) ) }On Friday 13 February 2009 18:42:26 Max Ischenko wrote: I get an error when I'm trying tu run this: stmt = text(select * from salary_data_new where codeword=:codeword union select * from

[sqlalchemy] single table inheritance : query a subtype and its subtypes

2009-02-13 Thread GustaV
Hello! In a configuration looking like this: class Parent: pass class Child(Parent): pass class ChildChild(Child): pass I would like to query the Childs and all classes that inherits it (here: ChildChild), but not Parent instances. session.query(Child).all() returns Child type only (

[sqlalchemy] Re: single table inheritance : query a subtype and its subtypes

2009-02-13 Thread az
session.query(Child).filter( Child.type != 'childtypenamehere') ? On Friday 13 February 2009 19:05:52 GustaV wrote: Hello! In a configuration looking like this: class Parent: pass class Child(Parent): pass class ChildChild(Child): pass I would like to query the Childs and

[sqlalchemy] Re: single table inheritance : query a subtype and its subtypes

2009-02-13 Thread az
ah sorry, singleinh, ignore my post On Friday 13 February 2009 19:05:52 GustaV wrote: Hello! In a configuration looking like this: class Parent: pass class Child(Parent): pass class ChildChild(Child): pass I would like to query the Childs and all classes that inherits it

[sqlalchemy] Re: Reg: Question on SqlAlchemy Speed

2009-02-13 Thread koranthala
On Feb 13, 8:20 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 13, 2009, at 10:08 AM, Michael Bayer wrote: On Feb 13, 2009, at 4:07 AM, koranthala wrote: Hi,   I am working on a Python application which does approximately 1000 updates  at a time every 3 seconds in a

[sqlalchemy] Re: dev: dialect reflection methods

2009-02-13 Thread Randall Smith
I started implementing this and it seemed a bit pointless because it just moves logic from one method (reflecttable) to several (reflect_columns, refelct_primary_keys, etc) without much benefit. The only immediate benefit I can see is that it may eliminate some redundancy. For example,

[sqlalchemy] Re: dev: dialect reflection methods

2009-02-13 Thread Michael Bayer
sorry I havent had the time to comment. though the resolution seems reasonable. On Feb 13, 2009, at 1:29 PM, Randall Smith wrote: I started implementing this and it seemed a bit pointless because it just moves logic from one method (reflecttable) to several (reflect_columns,

[sqlalchemy] Many-to-many, same table, association objects.

2009-02-13 Thread Stephen Hansen
Hi, all. I'm trying to get a many-to-many relationship, where each side of that relationship is the same table, and where there's an association object between them to hold data about the particular relationship. I'm using SQLAlchemy 0.5rc4. From the examples on the documentation, and some

[sqlalchemy] Re: Many-to-many, same table, association objects.

2009-02-13 Thread Michael Bayer
On Feb 13, 2009, at 1:46 PM, Stephen Hansen wrote: Hi, all. I'm trying to get a many-to-many relationship, where each side of that relationship is the same table, and where there's an association object between them to hold data about the particular relationship. I'm using SQLAlchemy

[sqlalchemy] Re: Many-to-many, same table, association objects.

2009-02-13 Thread Stephen Hansen
The first step would be to configure the inheritance hiearchy of Things, as I see you have an Asset table in there as well which I'm assuming is a Thing subclass. The joined table inheritance section in the docs will explain that. then you just set up relations using the same techniques

[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread Chris Withers
Michael Bayer wrote: session .query(Record).with_parent(unit).order_by(Record.date.desc()).first() OK, this works... alternatively, to do exactly what you stated above, i.e. unit.records.order_by()... etc., you can use a dynamic relation which establishes relations as Query objects.

[sqlalchemy] Re: Many-to-many, same table, association objects.

2009-02-13 Thread Michael Bayer
On Feb 13, 2009, at 2:09 PM, Stephen Hansen wrote: The first step would be to configure the inheritance hiearchy of Things, as I see you have an Asset table in there as well which I'm assuming is a Thing subclass. The joined table inheritance section in the docs will explain that. then

[sqlalchemy] Re: Finding the latest matching object from a relationship?

2009-02-13 Thread Michael Bayer
On Feb 13, 2009, at 2:12 PM, Chris Withers wrote: Michael Bayer wrote: session .query(Record).with_parent(unit).order_by(Record.date.desc()).first() OK, this works... alternatively, to do exactly what you stated above, i.e. unit.records.order_by()... etc., you can use a dynamic

[sqlalchemy] Re: single table inheritance : query a subtype and its subtypes

2009-02-13 Thread Michael Bayer
On Feb 13, 2009, at 12:05 PM, GustaV wrote: Hello! In a configuration looking like this: class Parent: pass class Child(Parent): pass class ChildChild(Child): pass I would like to query the Childs and all classes that inherits it (here: ChildChild), but not Parent