<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Querying the Context</title>
	<atom:link href="http://nerd.metrocat.org/2005/11/querying-the-context/feed" rel="self" type="application/rss+xml" />
	<link>http://nerd.metrocat.org/2005/11/querying-the-context</link>
	<description>You're reading Jeff Watkins' thoughts about Web application design and development with a little bit of technology ranting thrown in for free.</description>
	<lastBuildDate>Sun, 08 Jun 2008 07:06:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Bob Ippolito</title>
		<link>http://nerd.metrocat.org/2005/11/querying-the-context/comment-page-1#comment-91</link>
		<dc:creator>Bob Ippolito</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://nerd.metrocat.org/2005/11/querying-the-context#comment-91</guid>
		<description>&lt;p&gt;If you want to use a subset of Python to do it then take a look at what PJE does in RuleDispatch.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If you want to use a subset of Python to do it then take a look at what PJE does in RuleDispatch.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Brewer</title>
		<link>http://nerd.metrocat.org/2005/11/querying-the-context/comment-page-1#comment-92</link>
		<dc:creator>Robert Brewer</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://nerd.metrocat.org/2005/11/querying-the-context#comment-92</guid>
		<description>&lt;p&gt;There a a couple of ways to go in Dejavu, but here&#039;s what I&#039;d probably start with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Page(Unit):
    name = UnitProperty()

    def last_mod(cls, sandbox=None):
        if sandbox is None:
            sandbox = arena.new_sandbox()

        e = sandbox.view(Entry, (&#039;lastModified&#039;, &#039;page&#039;))
        if e:
            e.sort()
            lastmod, lastpage = e[-1]
            return sandbox.unit(cls, ID=page)
        else:
            return None
    last_mod = classmethod(last_mod)

class Entry(Unit):
    data = UnitProperty()
    page = UnitProperty(int)
    lastModified = UnitProperty(datetime.datetime)

Page.one_to_many(&quot;ID&quot;, Entry, &#039;page&#039;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;One of these days, we&#039;ll add support for aggregators like MAX and MIN.. :/&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>There a a couple of ways to go in Dejavu, but here&#8217;s what I&#8217;d probably start with:</p>

<pre><code>class Page(Unit):
    name = UnitProperty()

    def last_mod(cls, sandbox=None):
        if sandbox is None:
            sandbox = arena.new_sandbox()

        e = sandbox.view(Entry, ('lastModified', 'page'))
        if e:
            e.sort()
            lastmod, lastpage = e[-1]
            return sandbox.unit(cls, ID=page)
        else:
            return None
    last_mod = classmethod(last_mod)

class Entry(Unit):
    data = UnitProperty()
    page = UnitProperty(int)
    lastModified = UnitProperty(datetime.datetime)

Page.one_to_many("ID", Entry, 'page')
</code></pre>

<p>One of these days, we&#8217;ll add support for aggregators like MAX and MIN.. :/</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Shalabh</title>
		<link>http://nerd.metrocat.org/2005/11/querying-the-context/comment-page-1#comment-93</link>
		<dc:creator>Shalabh</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://nerd.metrocat.org/2005/11/querying-the-context#comment-93</guid>
		<description>&lt;p&gt;Interestingly, for this special case, the following solution works in &lt;a href=&quot;http://www.qlime.org/&quot;&gt;QLime&lt;/a&gt; (assuming you have two tables with one PK-FK relation):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;for page in Page.search(sort_on=(Reversed(Page.entries.lastModified),),
                        limit=1):
    latest_page = page
    break
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This fires exactly one SQL query and loads the page and all associated entries. Here&#039;s another solution -  first find the latest entry and then the associated page. This would work even if entries was a &#039;lazy&#039; attribute:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;for entry in Entry.search(sort_on=(Reversed(Entry.lastModified),), limit=1):
    latest_entry = entry
    break

latest_page = Page.find_one(entries=latest_entry)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&#039;m wondering why something like above would not be possible in SQLObject, or is it that an Entry may exist for classes other than Page?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Interestingly, for this special case, the following solution works in <a href="http://www.qlime.org/">QLime</a> (assuming you have two tables with one PK-FK relation):</p>

<pre><code>for page in Page.search(sort_on=(Reversed(Page.entries.lastModified),),
                        limit=1):
    latest_page = page
    break
</code></pre>

<p>This fires exactly one SQL query and loads the page and all associated entries. Here&#8217;s another solution &#8211;  first find the latest entry and then the associated page. This would work even if entries was a &#8216;lazy&#8217; attribute:</p>

<pre><code>for entry in Entry.search(sort_on=(Reversed(Entry.lastModified),), limit=1):
    latest_entry = entry
    break

latest_page = Page.find_one(entries=latest_entry)
</code></pre>

<p>I&#8217;m wondering why something like above would not be possible in SQLObject, or is it that an Entry may exist for classes other than Page?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Runar Petursson</title>
		<link>http://nerd.metrocat.org/2005/11/querying-the-context/comment-page-1#comment-94</link>
		<dc:creator>Runar Petursson</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://nerd.metrocat.org/2005/11/querying-the-context#comment-94</guid>
		<description>&lt;p&gt;Currently using SQLString, my single minded library to build SQL Strings, the syntax for the would be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;run(rm.user + rm.address.where(rm.address.city == &quot;NewBuryport&quot;))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Without any previous definition.  This returns a Query result, wrapped in a nice iterable object.&lt;/p&gt;

&lt;p&gt;In my yet-to-be-written ORM I&#039;d like the classes to be tied to relations (views), not relvars (tables).  This allows for a more natural mapping between Objects (which often span multiple tables) and the Relational Model.  The syntax might be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class UserRecord(relation):
    &quot;&quot;&quot;
    % user join address
    &quot;&quot;&quot;

m = UserRecord.where(&quot;address1 = &#039;NewBuryport&#039;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or (page case)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class NewestPage(relation):
&quot;&quot;&quot;
This is a class whose instances always contain the newest page.
% page join entry where lastModified = (entry over max(lastModified))
&quot;&quot;&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The relation is expressed in the doc string.  Of course my dream ORm has a built in Tutorial-D parser, so I can write elegant expressions and have them work.  There&#039;s no reason this couldn&#039;t create an object that was then updateable to the original tables in question.  There are a ton of other doors that open up too, like taking two random runtime instances and joining them, or inserting one &quot;set&quot; into another one of the same type.  The idea is mostly based on Date&#039;s work and the third manifesto.&lt;/p&gt;

&lt;p&gt;There are a lot of issues to work out, but I think it&#039;s an elegant way to solve the recurring query issue of ORM&#039;s.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Currently using SQLString, my single minded library to build SQL Strings, the syntax for the would be:</p>

<pre><code>run(rm.user + rm.address.where(rm.address.city == "NewBuryport"))
</code></pre>

<p>Without any previous definition.  This returns a Query result, wrapped in a nice iterable object.</p>

<p>In my yet-to-be-written ORM I&#8217;d like the classes to be tied to relations (views), not relvars (tables).  This allows for a more natural mapping between Objects (which often span multiple tables) and the Relational Model.  The syntax might be:</p>

<pre><code>class UserRecord(relation):
    """
    % user join address
    """

m = UserRecord.where("address1 = 'NewBuryport')
</code></pre>

<p>or (page case)</p>

<pre><code>class NewestPage(relation):
"""
This is a class whose instances always contain the newest page.
% page join entry where lastModified = (entry over max(lastModified))
"""
</code></pre>

<p>The relation is expressed in the doc string.  Of course my dream ORm has a built in Tutorial-D parser, so I can write elegant expressions and have them work.  There&#8217;s no reason this couldn&#8217;t create an object that was then updateable to the original tables in question.  There are a ton of other doors that open up too, like taking two random runtime instances and joining them, or inserting one &#8220;set&#8221; into another one of the same type.  The idea is mostly based on Date&#8217;s work and the third manifesto.</p>

<p>There are a lot of issues to work out, but I think it&#8217;s an elegant way to solve the recurring query issue of ORM&#8217;s.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Kozlovsky</title>
		<link>http://nerd.metrocat.org/2005/11/querying-the-context/comment-page-1#comment-95</link>
		<dc:creator>Alexander Kozlovsky</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://nerd.metrocat.org/2005/11/querying-the-context#comment-95</guid>
		<description>&lt;blockquote&gt;
  &lt;p&gt;Were I writing a C++ or Java library,
  Iâ€™d know where to go for a good parser generator.
  But whatâ€™s the tool of choice for Python?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I think ToyParserGenerator is the most Pythonic solution.
&lt;a href=&quot;http://christophe.delord.free.fr/en/tpg/&quot; rel=&quot;nofollow&quot;&gt;http://christophe.delord.free.fr/en/tpg/&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote>
  <p>Were I writing a C++ or Java library,
  Iâ€™d know where to go for a good parser generator.
  But whatâ€™s the tool of choice for Python?</p>
</blockquote>

<p>I think ToyParserGenerator is the most Pythonic solution.
<a href="http://christophe.delord.free.fr/en/tpg/" rel="nofollow">http://christophe.delord.free.fr/en/tpg/</a></p>]]></content:encoded>
	</item>
</channel>
</rss>
