On Mar 17, 2006, at 8:18 AM, Qvx 3000 wrote:
1. If I replace all those INSERTs and create_campaign with SA
objects nothing is written to database prior to calling
cc_util.process_campaign_import. The matter is even worse because I
need ID's for processing but they are not yet available. If I call
commit to make sure objects are in database (inserted) and that IDs
are available, I cannot ROLLBACK this in case of error. The real
question is maybe: How to do insert without database COMMIT?
well it seems like the approach youve taken with your application is
having somewhat of a clash with the application approach fostered by
SQLAlchemy's ORM. The general idea with the SA ORM is that you
worry about your objects and associating them together, but you
typically never need to deal with the primary keys explicitly, those
are handled for you.
However, if you do need the IDs explicitly, just create them
yourself, using a sequence, stored procedure, or whatever, and assign
that to the appropriate ID attribute on your object. When it gets
INSERT'ed by the ORM, thats the ID that will be used. the defaults
you create on Columns can be executed manually , i.e.
id = mytable.c.mycolumn.default.execute()
(more for the docs....)
2. Creating objects. Sometimes to create an object is nothing more
than inserting it into database, but sometimes it takes much more.
This is the reason that for most of my objects I have stored
procedures that create them. You might say use triggers, but this
system is accessed not only from this Python (semi-experimental)
app. My typical response to this is similar to create_campaign
function: I call store procedure, take back ID, fetch object via
Campaign.get(id), return object. Can I somehow move this into
__init__ or do it better in some other way? Those create_x
functions are annoying.
What are the stored procedures doing that is necessary ? can those
concepts be replaced by simpler ideas such as plain table
relationships ? do the stored procedures completely supercede the
need to call INSERT on the table, or are you looking for a "pre" or
"post" phase to a particular INSERT ? The easiest way would be via
MapperExtensions ( http://www.sqlalchemy.org/docs/
adv_datamapping.myt#adv_datamapping_extending ). These will let you
execute something before/after each INSERT (more hooks can be added
to this as well).
3. Calling stored procedures in not so verbose and explicit way.
youre talking about the fact that OUT parameters are not supported
yet, right ?
Maybe there are some answers in docs, but I've already read it once
top to bottom (not remembering everything). Now I'm just doing
well, your app is constructed very differently from the typical ORM-
styled application. I would take a look at the ZBlog demo app in
Myghty to see what I had in mind with the ORM, maybe youd get some
ideas on how to "bridge" your architecture to something more along
those lines (or maybe youre beyond that). Also consider that the
ORM is optional; if youre only using small pieces of it, you might
want to use the SQL construction by itself, or maybe just use mappers
to SELECT but your own method to insert records, etc., if in fact
your stored procedures are handling the issue of dependent objects.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users