[sqlalchemy] Re: Table updates using data mapping

2007-06-27 Thread voltron

Thanks Mike, that clears up a few things

On Jun 27, 2:08 am, Mike Orr [EMAIL PROTECTED] wrote:
 On 6/26/07, voltron [EMAIL PROTECTED] wrote:

  sess = create_session()
  allusers = sess.query(User).select()

  for user in allusers:
  user.group = contractor
  print x.name

 This adds the overhead of creating a Python object for every row.  If
 you already have many of the objects in memory anyway or the overhead
 is too small to be noticeable, you can do it this way.  Rick's way
 sends one small query to the database, which does it all internally.

 --
 Mike Orr [EMAIL PROTECTED]


--~--~-~--~~~---~--~~
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: Table updates using data mapping

2007-06-26 Thread Rick Morrison
Updates and inserts on the ORM side of the street are single-object kinds of
things. The pattern is to load a list of objects, make the appropriate
modifications to the those in-memory objects, and then issue a session
flush().

This type of
bulk operation is best done with the SQL generation portion of the library,
like so (using an implicit bound connection here):

   users.update(users.c.group == contractor).execute({users.c.group =
consultant})





On 6/26/07, voltron [EMAIL PROTECTED] wrote:


 Could someone tell me how I would execute this SQL using data mapping?

 # SQL

 UPDATE users SET group=consultant WHERE group = contractor;

 #  Mapped object
 user_mapper = mapper(User, users)
 user = User()


 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: Table updates using data mapping

2007-06-26 Thread voltron

would I have to do something like this?

sess = create_session()
allusers = sess.query(User).select()


for user in allusers:
user.group = contractor
print x.name


On Jun 26, 10:40 pm, voltron [EMAIL PROTECTED] wrote:
 Could someone tell me how I would execute this SQL using data mapping?

 # SQL

 UPDATE users SET group=consultant WHERE group = contractor;

 #  Mapped object
 user_mapper = mapper(User, users)
 user = User()

 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: Table updates using data mapping

2007-06-26 Thread Michael Bayer


On Jun 26, 2007, at 4:51 PM, Rick Morrison wrote:

 Updates and inserts on the ORM side of the street are single-object  
 kinds of things. The pattern is to load a list of objects, make the  
 appropriate modifications to the those in-memory objects, and then  
 issue a session flush().

 This type of bulk operation is best done with the SQL generation  
 portion of the library, like so (using an implicit bound connection  
 here):

users.update(users.c.group == contractor).execute({users.c.group  
 = consultant})


using the actual execution terminology i made up !  nice



--~--~-~--~~~---~--~~
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: Table updates using data mapping

2007-06-26 Thread Mike Orr

On 6/26/07, voltron [EMAIL PROTECTED] wrote:
 sess = create_session()
 allusers = sess.query(User).select()


 for user in allusers:
 user.group = contractor
 print x.name

This adds the overhead of creating a Python object for every row.  If
you already have many of the objects in memory anyway or the overhead
is too small to be noticeable, you can do it this way.  Rick's way
sends one small query to the database, which does it all internally.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---