Hi,

> Because if you "bind a session to a class", it means you want all
> instances of that class to use that same session. For that to happen,
> you need the class __init__ method to be instrumented in such a way
> that the instance is automatically added to the session when it is
> created. Only ScopedSession provides that functionality.

Maybe I miss some details about scoped sessions, but in a 
single-session, shared by threads scenario I'd like to see the same. The 
scoped sessions - according to 
http://www.sqlalchemy.org/docs/05/session.html#unitofwork_contextual
  - just add the "one session per thread to bind them all"-property.

So if Elixir would allow for "normal" sessions, what wouldn't work?

>> A class primarily defines things that eventually become part of the
>> metadata. Where is the session involved in that?
> 
> The session is involved in the "mapping process" only if the session
> is a ScopedSession. In that case the mapping between the class and the
> table is done through session.mapper(class_, table), which provides
> the instrumentation described above.
> 
>> An *instance* needs always a session, that much is clear to me.
> 
> Not entirely true. It's true that an instance will have one as soon as
> it is created if you work with a scoped session.
> 
>> If the scoped session for a class is needed for convenience reasons - the
>> implicit session management otherwise being not possible
> 
> Indeed, that's the case. But as I said, you can work without a
> ScopedSession if you want.
> 
>> However, then at least the error-message might become somewhat more clear,
>> stating that in case of a non-scoped session, the user needs to pass None &
>> uses explicit session management.
> 
> I guess the "or None" is not enough here...
> 
>             raise Exception("Failed to map entity '%s' with its table or "
>                             "selectable. You can only bind an Entity to a "
>                             "ScopedSession object or None."
>                             % self.entity.__name__)
> 
> Any idea how to improve the message?
>

Hm, maybe "or None for manual session managment."

>> BTW, is there any docs showing this?
> 
> Yes, though it is only a one-line sentence which is probably cryptic
> to the non initiate.
> See the "session" option in:
> http://elixir.ematia.de/apidocs06/elixir.options.html
> 
> If you have suggestions for a better wording, I'd be glad to hear them...

"""
In the later case your entity will be mapped using a non-contextual mapper.

This allows for manual session management, as seen in pure SQLAlchemy. 
You then can share objects threads, as long as you guarantee that only 
one thread accesses a session at the same time.
"""

> A FAQ (or Recipe?) would probably be a good idea too, though I'm
> lacking inspiration as to how to word the question so that people
> looking for it would find it.
>

That's a tough one, sure. But

"Is it possible to share objects between threads?"

might be a candidate.

Diez


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

Reply via email to