On Jan 16, 2006, at 1:01 PM, David Geller wrote:
1. using the mapper, how is it best to delete a record?
a) You have an object that is mapped. I tried the python "del" and
that didn't appear to work. objectstore.delete(obj) *did* work.
at the moment, thats how it works. im not sure if "del object" is
really the best way, since in SQLAlchemy your object instance is
*not* synonymous with a row. you can create objects without an
INSERT, therefore you should be able to delete objects without a DELETE.
if you also use the "assign_mapper" function I think you can also say
obj.delete() which is the same thing....I might consider overriding
del in the case of the assign_mapper usage, since using assign_mapper
indicates you want the "quick and easy" methods set up for your class.
b) You don't have an object - you merely want to delete a bunch of
records based on a "where".
# delete where col1=5
mytable.delete(mytable.c.col1==5).execute()
2. Similar to 1b), how do you *update* a record or bunch of records
without having to have the objects, using the mapper? (i.e, I want
to use "update" with a "where")
# update set col3=10 where col1=5
mytable.update(mytable.c.col1==5).execute(mytable.c.col3 = 10)
There are a few other syntaxes for 'delete', 'update', and 'insert',
described in the vicinity of http://www.sqlalchemy.org/docs/
sqlconstruction.html#sql_update .
It seems though, that you are looking for some kind of update/delete/
insert at the mapper level. While I could add a more 'mapper'-ized
version of the above methods to the mapper, it would be a feature
that is inherently broken, since if the mapper just uses straight
updates and deletes to modify things, it has no way to update
dependent objects, or of knowing if its going to violate constraints
if it cant load all the corresponding data into memory. it doesnt
have the ability to aggregate stuff like that into additional en-
masse queries. although i suppose its possible to add such a feature
since it knows the general dependency relationships. it would be a
large undertaking probably better left after this thing has some
releases going.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users