[Grok-dev] Re: grok and the ORM of your choice
Brandon Craig Rhodes
brandon at rhodesmill.org
Thu Aug 2 13:17:28 EDT 2007
Martijn Faassen <faassen at startifact.com> writes:
> Hey Brandon,
> Some belated feedback to this.
Thank you! I had worried that it simply did not merit comment. :-)
> If you're still interested, I'd be very happy if you could turn this
> into a tutorial so we can put it online!
PvW suggested the same thing yesterday - I will try to get this
written up within the next week!
>> import sqlalchemy as sa
>> engine = sa.create_engine('postgres://localhost/mage')
> I'm surprised you didn't need to integrate with Zope's transaction
> machinery, so that a commit automatically happens at the end of a
I am thinking of being Web-2.0-ish and have mutable operations occur
only in XML-RPC functions - in which case, I could simply do commits
by hand as the last statement of each XML-RPC function.
But, as you mention, there already exists "zalchemy" which makes
SQLAlchemy work magically with Zope transactions. I had done a Google
search and gotten confused trying to apply "z3c.sqlalchemy" to my
situation, before PvW mercifully pointed me at "zalchemy" (which I had
not heard of before) yesterday.
> I really tried to make z3c.zalchemy work as I know Christian Theune
> worked on this (ZODB integration expert and one of the original Grok
> developers), but unfortunately I couldn't get it figured out for my
> use case.
Actually, "zalchemy" seemed almost easy - but maybe that was only
after looking at z3c.sqlalchemy! :-)
I got "zalchemy" working last night in about two hours; my only
hang-up was needing to open a special session during application
instantiation so that I could have SQLAlchemy introspect the structure
of my tables. But, I have so far only used it for reading - I cannot
confirm yet that the way I have configured it works and commits
changes I make to the database. I should know that by the end of
I will describe how I used "zalchemy" in my tutorial.
>> the name "index". That name seems to be special inside of Zope 3;
>> while one can see an object by adding "index" to the URL explicitly
>> like ".../person/900010011/index", it also appears to be the view
>> that is used if no view name is added to the end of the URL at all
>> like "../person/900010011".
> Yes, this is in fact deliberate and intended. We may add a
> grok.default_view() directive to make this more clear.
I actually like the "index" convention, because it "Works Just Like
Apache And Everything Else". Introducing a default_view() call would
mean I have to go look up which view is default, rather than "just
knowing" by looking at the names.
> I heard at the post-EuroPython sprint that there is some work done
> on a hook in Zope 3 that allows you to run without ZODB. I don't
> know the details on this hook, but perhaps Philipp knows. Philipp?
I heard rumors as well, perhaps from Boston, of someone running pure
Subversion behind some kind of Zope, with no ZODB at all.
>> But I'm not yet savvy enough to know how this applies to Grok;
>> how do I write a script that imports and uses my Grok Models?
> One thing you should try is:
> bin/zopectl debug
> You'll get a python prompt and 'root' is the name of the root object
> of Zope.
I'll look at how it is designed and see what I can figure out.
I will see whether I have time this weekend for writing a tutorial.
Brandon Craig Rhodes brandon at rhodesmill.org http://rhodesmill.org/brandon
More information about the Grok-dev