<div>using <span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">storm orm(twisted version) in Nevow:</span></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Here is my approach:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">First, create a pool:</span></font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans">
<span style="color: #0000ff">from</span> storm.databases.sqlite <span style="color: #0000ff">import</span> SQLite</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span style="color: #0000ff">from</span> storm.uri <span style="color: #0000ff">import</span> URI</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span style="color: #0000ff">from</span> storm.twisted.store <span style="color: #0000ff">import</span> StorePool</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans">
<br></p></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans">
database = SQLite(URI(<span style="color: #00aa00"><i>&#39;sqlite:///test.db&#39;</i></span>))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans">pool = StorePool(database, <span style="color: #800000">2</span>, <font class="Apple-style-span" color="#800000">5</font>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans">pool.start()</p></span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br>
</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br>
</span></font></div><div>In pages, we can use store in render functions like:</div><div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #0000ff">def</span> <b>render_PeopleList</b>(<i>self</i>, ctx, data):</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                </span>pat = inevow.IQ(ctx).patternGenerator(<span style="color: #00aa00"><i>&#39;PeopleItem&#39;</i></span>)</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000ff">def</span> <b>cb_find</b>(results, s):</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span>results.config(offset=<span style="color: #800000">0</span>, limit=<span style="color: #800000">10</span>)</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #0000ff">return</span> results.all().addCallback(cb_all, s)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans; min-height: 16.0px"><span class="Apple-tab-span" style="white-space:pre">                </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000ff">def</span> <b>cb_all</b>(items, s):</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #c0c0c0">#recycle this store.</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span>pool.put(s)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span>ps = []</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #0000ff">for</span> item <span style="color: #0000ff">in</span> items:</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                                </span>p = pat()</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                                </span>p.fillSlots(<span style="color: #00aa00"><i>&#39;nickname&#39;</i></span>, item.nickname)</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                                </span>ps.append(p)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans; min-height: 16.0px"><span class="Apple-tab-span" style="white-space:pre">                        </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #0000ff">return</span> ctx.tag[ ps ]</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans; min-height: 16.0px"><span class="Apple-tab-span" style="white-space:pre">                </span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000ff">def</span> <b>cb_get</b>(s):</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #0000ff">return</span> s.find(User).addBoth(cb_find, s)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Panic Sans"><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #0000ff">return</span> pool.get().addCallback(cb_get).addErrback(<span style="color: #0000ff">lambda</span> error: log.msg(error))</p>
</div><div><br></div><div>That&#39;s it.</div><div><br></div><div>Thank you guys for help.</div><div><br></div><div>FYI: Storm ORM with twisted integration is not quite stale yet.</div><div><br></div><br><div class="gmail_quote">
On Thu, Jul 9, 2009 at 10:18 AM, Daniel Yang <span dir="ltr">&lt;<a href="mailto:daniel.yang.zhenyu@gmail.com">daniel.yang.zhenyu@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Thanks, Tristan and Colin.</div><div>Yes. the code was taken from storm unittests.</div><div><br></div><div>I was planning to do some rendering work in <span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">cb_result.</span></div>

<div><font face="arial, sans-serif"><span style="border-collapse:collapse">Let me try first.</span></font></div><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Thu, Jul 9, 2009 at 9:59 AM, Tristan Seligmann <span dir="ltr">&lt;<a href="mailto:mithrandi@mithrandi.net" target="_blank">mithrandi@mithrandi.net</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Jul 9, 2009 at 3:30 AM, Daniel Yang&lt;<a href="mailto:daniel.yang.zhenyu@gmail.com" target="_blank">daniel.yang.zhenyu@gmail.com</a>&gt; wrote:<br>


&gt; def test_execute(self):<br>
<br>
This looks like a unit test, not Nevow code?<br>
<div><br>
&gt;     def cb_execute(result):<br>
&gt;         #this result is a DeferredResult, not the actual data.<br>
&gt;         return result.get_one().addCallback(cb_result)<br>
&gt;     def cb_result(result):<br>
&gt;         #the data returns<br>
&gt;          print result<br>
<br>
</div>Return your ultimate result here; note that if you&#39;re not actually<br>
going to do anything to result in cb_result, you could just have:<br>
<br>
def cb_execute(result):<br>
    return result.get_one()<br>
<div><br>
&gt;     self.store.execute(&quot;SELECT title FROM foo WHERE id=10&quot;).addCallback(cb_execute)<br>
&gt;     return ?<br>
<br>
</div>return self.store.execute(&quot;SELECT title FROM foo WHERE<br>
<div>id=10&quot;).addCallback(cb_execute)<br>
<br>
</div>The result returned from cb_result is what will ultimately used by<br>
whatever invoked test_execute, assuming that it pays attention to the<br>
return value; I&#39;m not clear how test_execute is being used, so I can&#39;t<br>
say this will work for sure. If test_execute is, for example, a render<br>
method, then it should work just fine.<br>
<font color="#888888">--<br>
mithrandi, i Ainil en-Balandor, a faer Ambar<br>
</font><div><div></div><div><br>
_______________________________________________<br>
Twisted-web mailing list<br>
<a href="mailto:Twisted-web@twistedmatrix.com" target="_blank">Twisted-web@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div>-- <br>-----------------------------------------------<br>Yours<br>Faithfully<br><font color="#888888"><br>Daniel Yang<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>-----------------------------------------------<br>Yours<br>Faithfully<br><br>Daniel Yang<br>