[Twisted-web] A question with storm orm and Nevow

Daniel Yang daniel.yang.zhenyu at gmail.com
Wed Jul 8 21:30:31 EDT 2009

Thanks, Colin.

In my case, I have to take 2 steps to get data from database.
1. execute sql, get a DeferredResult instance.
2. use DeferredResult.get_all/one() to get the real data.

it is a more complicated process than just one deferred.

def test_execute(self):
    def cb_execute(result):
        #this result is a DeferredResult, not the actual data.
        return result.get_one().addCallback(cb_result)

    def cb_result(result):
        #the data returns
         print result

    self.store.execute("SELECT title FROM foo WHERE

    return ?

What should I return?

I execute sql statements directly using store. Possibly it is not a good
If I use the ORM way:

    def test_get(self):
        Try to get an object from the store and check its attributes.
        def cb(result):
            self.assertEquals(result.title, u'Title 30')
            self.assertEquals(result.id, 10)
        return self.store.get(Foo, 10).addCallback(cb)

That'd be much easier.

On Wed, Jul 8, 2009 at 11:22 PM, Colin Alston <karnaugh at karnaugh.za.net>wrote:

> On Wed, Jul 8, 2009 at 5:21 PM, Colin Alston <karnaugh at karnaugh.za.net>wrote:
>> On Wed, Jul 8, 2009 at 4:59 PM, Daniel Yang <daniel.yang.zhenyu at gmail.com
>> > wrote:
>>> Hi people,
>>> I am using storm orm(twisted-integration) with Nevow.
>>> There is a question that confuses me a lot:
>>> (since storm orm(twisted-integration) does db io in a asynchronous way).
>>> In a render function, before my data returns, what should I return for
>>> the render function?
>>> does Nevow has something like server.NOT_DONE_YET?
>>> or there is a "deferred" way to do this?
>> Hi,
>> You can simply use a deferred in any render function as you would expect.
>> Nevow deals with this for you.
>> def render_foo(self, ctx, data):
> Wow.. Google mail fails and I'm too used to using TAB when writing code...
> def render_foo(self, ctx, data):
>    def continueRendering(results):
>        # do something with results
>        return ctx.tag[whatever]
>    return myDeferredDatabaseQuery(some args).addBoth(continueRendering)
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web


Daniel Yang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20090709/fe61ae9e/attachment.htm 

More information about the Twisted-web mailing list