On Jun 15, 11:23 am, bsmedberg <[EMAIL PROTECTED]> wrote:
>
> 1) is it possible to perform queries with no default session? That is,
> the instances returned will be detached automatically

create_session().query(Whatever).filter(...).all()

the session falls out of scope immediately.

>
> 2) is it possible to have instance objects be readonly in some cases?
> That is, when performing readonly actions, attempting to set
> properties on the instance object will raise an error?

create your own "property" objects that raise the error and return the
mapped properties.  create the mapper using the "column_prefix"
argument that will precede all mapped properties with a character such
as an underscore "_".

Somebody on IRC
> pointed me at using multiple mappers for the same class, but I'm not
> sure this does what I want because the docs say "Objects that are
> loaded with a secondary mapper will have their save operation
> processed by the primary mapper"

a class is only mapped to one table or group of tables.  if you want
instances of classes saved in different tables arbitrarily, create
mappers using "entity_name".  no idea what this has to do with read-
only attributes, though.

>
> 3) Is creating/deleting a session an expensive operation? Could I for
> example create a new session for each HTTP request and then just get
> rid of it at the end of the request without explicitly clearing it?

this is exactly how you have to use sessions with a web application,
at the very least, since a single session cannot be shared among
threads.  a session is just an object instance with a couple of
dictionaries in it, so sessions can be created at a much finer-grained
level of operation without concern for performance.

>
> 4) Can mapped instance objects be pickled safely? I tried to cache
> query results using myghty caching to file but it ends up leaking the
> objects that were pickled.

yes they can be pickled safely.  im not sure what you mean by
"leaking".

When the objects are unpickled, are they
> associated with the default session or are they created detached?

if the session to which they were attached still exists, then theyd
still be attached to that...its just a "_session_id" attribute on the
object referencing the session in a weakvaluedict.  otherwise theyre
detached.  put them back into a session using save_or_update() or
possibly merge().


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to