[sqlalchemy] Re: multiple mapper extensions

2007-08-01 Thread jason kirtland

Michael Bayer wrote:
 
 On Jul 30, 2007, at 4:58 PM, Jonathan LaCour wrote:
 
 Michael Bayer wrote:

 its a model taken from the way event loops usually work; any consumer
 along the event chain is allowed to say, ive consumed the event and
 stop further handlers from dealing with it. we can certainly change
 the names around into something less ridiculous. unfortuantely,
 changing it so that no return value, or None, does *not* short
 circuit the chain runs a slight risk that someone is actually using
 it that way.  So we might need to change it such that if your
 before_insert returns None, an error is raised, and youre forced to
 return a specific value indicating the next activity...otherwise
 someone's upgrade might silently fail.
 
 Fair enough, I suppose.  I think I can get over it, for the most part.
 It might just be an issue of cognitive dissonance because of the  
 naming
 convention or how its described in the documentation.
 
 
 i think a name change is probably in order at the very least.

r3130 in the trunk implements a name change- EXT_CONTINUE will propagate 
the hook to the next extension or back to the base implementation. 
EXT_STOP will halt propagation.

it's only a name and doc change:
EXT_CONTINUE = EXT_PASS = object()
EXT_STOP = object()

EXT_STOP is just a feel-good value.  the general rule of halt on any 
return value but EXT_CONTINUE is unchanged.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] all() or list() ?

2007-08-01 Thread Alexandre CONRAD

Hello,

I'm realizing that I've been using .list() to query objects. But all the 
examples in the docs talk about .all().

What's the difference ? Should I switch to .all() rather than .list() ? 
Will list be deprecated in 0.4 ?

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: all() or list() ?

2007-08-01 Thread Gaetan de Menten

On 8/1/07, Alexandre CONRAD [EMAIL PROTECTED] wrote:

 I'm realizing that I've been using .list() to query objects. But all the
 examples in the docs talk about .all().

 What's the difference ? Should I switch to .all() rather than .list() ?

 Will list be deprecated in 0.4 ?

Exactly. list() is the old way, all() is the 0.4 way.

-- 
Gaƫtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: all() or list() ?

2007-08-01 Thread Alexandre CONRAD

Gaetan de Menten wrote:
What's the difference ? Should I switch to .all() rather than .list() ?
Will list be deprecated in 0.4 ?
 
 Exactly. list() is the old way, all() is the 0.4 way.

Thanks Gaetan, I'll clean up my code to be compliant with 0.4.

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: multiple mapper extensions

2007-08-01 Thread Jonathan LaCour

jason kirtland wrote:

 i think a name change is probably in order at the very least.

 r3130 in the trunk implements a name change- EXT_CONTINUE will
 propagate the hook to the next extension or back to the base
 implementation.  EXT_STOP will halt propagation.

 it's only a name and doc change:  EXT_CONTINUE = EXT_PASS = object()
 EXT_STOP = object()

 EXT_STOP is just a feel-good value. the general rule of halt on any
 return value but EXT_CONTINUE is unchanged.

Perfect.  This now makes total sense, thanks for doing this!

--
Jonathan LaCour
http://cleverdevil.org


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: cannot read msg...

2007-08-01 Thread Alexandre CONRAD

yes

Glauco wrote:

 can someone read me?
 
 
 Glauco
 

-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] cannot read msg...

2007-08-01 Thread Glauco

can someone read me?


Glauco

-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software(r)  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] TypeError with 0.4 and python 2.3

2007-08-01 Thread Dan Watson

Right now, importing sqlalchemy on python 2.3 is broken. __name__ is
readonly in 2.3, so the import fails:

 from sqlalchemy import *
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /home/watsond/python_packages/sqlalchemy/__init__.py, line 9,
in ?
from sqlalchemy.schema import *
  File /home/watsond/python_packages/sqlalchemy/schema.py, line
1087, in ?
class MetaData(SchemaItem):
  File /home/watsond/python_packages/sqlalchemy/schema.py, line
1180, in MetaData
connect = util.deprecated(connect)
  File /home/watsond/python_packages/sqlalchemy/util.py, line 552,
in deprecated
func_with_warning.__name__ = func.__name__
TypeError: readonly attribute

I'm not sure what side-effects it would cause (my guess would be
harder-to-read tracebacks when calling deprecated methods?), but
commenting out the assignment got me up and running again.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: right outer join (newbie)

2007-08-01 Thread Michael Bayer


we currently dont have a right outer join.  but this is not by  
accident...theres really no use case for a right outer join, which  
are more easily written as left outer joins.

some good articles on whats wrong with RIGHT outer join as well as  
FULL outer join:

http://weblogs.sqlteam.com/jeffs/archive/2006/03/14/9289.aspx
http://weblogs.sqlteam.com/jeffs/archive/2007/04/19/Full-Outer- 
Joins.aspx?x=1



On Aug 1, 2007, at 5:56 PM, mc wrote:


 Hi,
 I read in the docs about joins and saw an example for left outer join,
 though I didn't understand where the left was specified.
 How is a right outer join specified?


 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Atomic update to balance in transaction with ORM changes

2007-08-01 Thread Nick Johnson

I have ORM mapped tables with a schema like the following:
---
Table 'users':
  user_id integer
  username text
  balance integer

Table 'products':
  product_id integer
  cost integer

Table 'user_products':
  user_id integer
  product_id integer
---

when a user buys a product, I need to add a user_product record for
them, and deduct the cost of the product from the user's balance. I
need to do the latter in an atomic fashion, however (eg, UPDATE users
SET balance = balance - ? WHERE user_id = ?) in the same transaction
as the ORM changes to create the user_products record. Ideally, I need
to update the relevant User object with the updated balance, too.

Can anyone provide me with a quick overview of how to do this?

Thanks,

Nick Johnson


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Atomic update to balance in transaction with ORM changes

2007-08-01 Thread Michael Bayer


On Aug 1, 2007, at 7:26 PM, Nick Johnson wrote:


 I have ORM mapped tables with a schema like the following:
 ---
 Table 'users':
   user_id integer
   username text
   balance integer

 Table 'products':
   product_id integer
   cost integer

 Table 'user_products':
   user_id integer
   product_id integer
 ---

 when a user buys a product, I need to add a user_product record for
 them, and deduct the cost of the product from the user's balance. I
 need to do the latter in an atomic fashion, however (eg, UPDATE users
 SET balance = balance - ? WHERE user_id = ?) in the same transaction
 as the ORM changes to create the user_products record. Ideally, I need
 to update the relevant User object with the updated balance, too.

 Can anyone provide me with a quick overview of how to do this?


if you use a SessionTransaction (which is being simplified in the  
next release), and then load your User with_lockmode as such:

user = session.query(User).with_lockmode('update').load(userid)

that will in all cases, whether userid was already loaded or not,  
issue a SELECT...FOR UPDATE on the row containing that user id, and  
it will overwrite all attributes on your User object with the values  
retrieved from the database.  so now, the balance attribute on  
'user' should be the latest value, and the row should be locked  
against further changes.

then, modify the balance attribute on your User object, modify  
other attributes as needed, and flush().  after that, commit the  
transaction.




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Atomic update to balance in transaction with ORM changes

2007-08-01 Thread Michael Bayer



On Aug 1, 8:35 pm, Nick Johnson [EMAIL PROTECTED] wrote:

 Thanks, I'll try that. Is there a way I can do this without locking,
 though, such as by adding my own UPDATE query to the transaction?


uh sure probably with a MapperExtension that does an after_update()
for the User mapper...just issues that SQL.

though with that arrangement, you need to be careful that the mapper
doesnt update the column beforehand with the balance value on your
User.

Theres a feature we've discussed which is probably the best way to do
this, you'd just say:  user.balance = user_table.c.balance + 1 ...the
mapper intercepts the ClauseElement and uses that as the UPDATE
value.  so maybe ill put that in 0.4.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Problem using multiple mappers for one class

2007-08-01 Thread Gabriel Cote

Hi,

I ran into an error trying to use two mappers for the same class. I
encounter the error AttributeError: type object 'MyObject' has no
attribute 'my_attribute'. Using the first mapper before creating the
other seems to corrupt the mapped class. Here is an example:

from sqlalchemy import *
from sqlalchemy.orm import *

uri = r'sqlite:///bug.db'

metadata = MetaData()

class AA(object):
pass


class BB(object):
pass


aa_table = Table('aas', metadata,
Column('id', Integer, primary_key=True),
Column('stuff', Integer, default=1))

bb_table = Table('bbs', metadata,
Column('id', Integer, primary_key=True),
Column('other_stuff', Integer, default=2),
Column('aa_id', Integer, ForeignKey('aas.id')))

aa_first_mapper = mapper(AA, aa_table, entity_name='first')
bb_first_mapper = mapper(BB, bb_table, entity_name='first')

aa_first_mapper.add_property('bbs', relation(bb_first_mapper,
backref='aa'))


def fill_db():
metadata.connect(uri)
metadata.bind.echo = False
session = create_session()

metadata.drop_all()
metadata.create_all()

aa1 = AA()
bb1 = BB()
bb1.aa = aa1
bb2 = BB()
bb2.aa = aa1
session.save(aa1, entity_name='first')
session.save(bb1, entity_name='first')
session.save(bb2, entity_name='first')

session.flush()
session.clear()

fill_db()

def access_db():
session = create_session()
aas = session.query(aa_first_mapper).select()
print 'bbs in aas[0] count =', len(aas[0].bbs)

access_db()

# commenting these 3 lines of code will fix the bug!?
aa_second_mapper = mapper(AA, aa_table, entity_name='second')
bb_second_mapper = mapper(BB, bb_table, entity_name='second')
aa_second_mapper.add_property('bbs', relation(bb_second_mapper,
backref='aa'))

access_db() # crash :(


From what I understand of the documentation, I should be able to do
this using different entity names for the different mappers. Or is it
that once an object has been committed to the db using a certain
entity name, it can only be manipulated with this same entity name?

Thanks


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Problem using multiple mappers for one class

2007-08-01 Thread Michael Bayer



On Aug 1, 9:45 pm, Gabriel Cote [EMAIL PROTECTED] wrote:

 From what I understand of the documentation, I should be able to do

 this using different entity names for the different mappers. Or is it
 that once an object has been committed to the db using a certain
 entity name, it can only be manipulated with this same entity name?


the only real problem with the above is that your second two mappers
are uncompiled.  this because you create them but don't reference them
in any way, and also because your usage of the mapped classes, which
also triggers a compile, precedes their creation so they didn't get
compiled there either.  either define them up above or just say
compile_mappers() and you're a go.

also, when an object is saved to the session with a particular entity
name (or loaded with that mapper), its got an _entity_name attribute
which marks it as linked to that mapper.  if you want to switch the
entity name around you can use obj = session.merge(obj,
entity_name=newname).


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---