On Jun 27, 7:44 pm, "Mike Orr" <[EMAIL PROTECTED]> wrote:
> The normal Pylons strategy is to clear the SQLAlchemy session in the
> base controller before calling the action method. This is effectively
> a rollback, but since all the changes are in memory and haven't been
> compiled to SQL yet, no rollback is necessary.
theres a rollback() going on ; SQLAlchemy's connection pool issues a
rollback() on all connections before theyre returned to the pool.
this is to release any locks that might be present on the connection
(and its definitely quite necessary...unless we went with the COMMIT
on every statement/connection returned idea someone has mentioned).
> Of course the engine must be initialized before any tables can be
> defined or any work done.
since ive seen people get the wrong idea about this, let me
reiterate: *you can define all your tables and mappers with no
database connection defined whatsoever*, and you can even start
creating mapped objects. SQLAlchemy does not care a whiff about your
database connection until the moment you tell it to execute a SQL
statement...and when the statement is done, it goes back to not caring
at all about your database connection; you can tear it down or modify
it to be something else all you like.
> SAContext initializes the default engine in
> the constructor. Is there a need to push that back to some later
> stage? Which stage? Or can Ian's ideal wrapper simply delay creating
> the 'sac' until it has to?
easy enough to make "uri" optional in SAContext (the way it is for
everything else in SA) and just allow binding it later via
add_engine() or whatever. SAContext is designed the way it is right
now because Pylons defines the default engine in the .ini file; theres
no need for a "delayed" connection in the usual case. im not exactly
sure why Jonathan thinks that the "url" forces one to "define my
connection up front". if youre saying, "i want to distribute the
application without an .ini file" thats fine...but when the thing is
actually *used*, there will be an .ini file or other configuration
defined when things run. if you want to define your model
independently of connection, just use an empty MetaData. Set up the
SAContext to bind the engine or individual connections to the session
instead...or give it your MetaData for it to bind when youre ready.
theres really nothing to it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---