From user-return-9080-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Tue Mar 02 19:12:36 2010 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 31901 invoked from network); 2 Mar 2010 19:12:36 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Mar 2010 19:12:36 -0000 Received: (qmail 35258 invoked by uid 500); 2 Mar 2010 19:12:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 35119 invoked by uid 500); 2 Mar 2010 19:12:30 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 35103 invoked by uid 99); 2 Mar 2010 19:12:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 19:12:30 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lewcid@gmail.com designates 74.125.83.180 as permitted sender) Received: from [74.125.83.180] (HELO mail-pv0-f180.google.com) (74.125.83.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Mar 2010 19:12:22 +0000 Received: by pvc22 with SMTP id 22so173417pvc.11 for ; Tue, 02 Mar 2010 11:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=4fHEHNZSWqMRkpCz6o3zY5HaQRTmxN7OIMn0JLj2ihc=; b=cNrJJae1yhZ+0cnfGxHXMWvo00TFtN8HhwP1TuOGomJzUUuD1ZytTaNd2fPXNQ7SkB IharSoHA114ZL49OtdnIn1wbdNh5v1Y/NVR2hYgJ2jOUJspbJiriruvoqqG5Etn9RWVA C0rhlJYJPPK+zG+hjVK7ncmhjwbTxAWCq6bNI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=Y6uXaTPuCN58WaIJ/eiQE/jAwPkI7MmRN3QQxrqKyRyUO8NCynV94WhqSYOJ+ZD2NS tafZuXFyGIsetdvKqjLlzuHo9IXNnDAemNB+wAKrtJ3T9JqRE/spKBF/ZAGMktNa5Txs cOh9/p3d0JbZ517QUNgE+c0cCnBPNqvCepItM= MIME-Version: 1.0 Received: by 10.141.106.11 with SMTP id i11mr3466691rvm.213.1267557119707; Tue, 02 Mar 2010 11:11:59 -0800 (PST) In-Reply-To: <21a5a18d1003021103m466b3363p9c549e25792f72af@mail.gmail.com> References: <21a5a18d1003021103m466b3363p9c549e25792f72af@mail.gmail.com> Date: Tue, 2 Mar 2010 20:11:59 +0100 Message-ID: Subject: Re: Implementing next and previous links From: Saq Imtiaz To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=000e0cd13b7ada4c3a0480d623fe X-Virus-Checked: Checked by ClamAV on apache.org --000e0cd13b7ada4c3a0480d623fe Content-Type: text/plain; charset=ISO-8859-1 Hi Sean! What a small world. Funny running in to you here! What are you using couchdb for? Yes the goal is for the application to be self-contained within couchdb so that replication for instance, copies the application logic and the data. I've had a very nice conversation with jchris on #couchdb and he's essentially confirmed my feeling that if I want prettier links than using ?startkey type urls, I'll need to rewrite them clientside after performing additional queries. If anyone else has different ideas on how to do this within the described constraints I'd be happy to hear them. Cheers, Saq On Tue, Mar 2, 2010 at 20:03, Sean Clark Hess wrote: > Hey Saq! It's been a while. How have you been? > > Is an application layer out of the question? > > On Tue, Mar 2, 2010 at 11:16 AM, Saq Imtiaz wrote: > > > Hi guys. I'm getting to know couchdb with an aim to writing a "blog-like" > > application where you display one post at a time. Posts have a > > chronological > > order and each post has "next post" and "previous post" links. > > > > I was hoping to get some input on the best way to implement these links. > > I've done a fair bit of reading on the wiki and mailing list archives > > (especially discussions around paging). I'm looking to create a couchapp > > where I can render the essential information as HTML in couchdb and only > > make additional requests from the clientside for comments. An additional > a > > consideration is that I'd like to be able to use the url rewriting in > > couchdb 0.11 to have "meaningful" links to each post, e.g.: /date/title > > (where title=docid) > > > > What I've done so far is to give each "post" document an id which > > corresponds to its title and a numerical "date_created" attribute. I have > a > > view function that emits ([doc.date_created,doc._id],doc) > > > > Then I load a specific page using myview?key=["201003021333","docid"] > > I suppose I can use the total_rows and offset to predict whether or not > > there should be next and previous links but I'm not sure if there are any > > hidden caveats here? > > > > For the next link I can use: > > myview?startkey=["201002261927010000"]&limit=1&skip=1 > > For the previous link: > > myview?startkey=["201002261927010000"]&limit=1&descending=true > > > > Alternatively I could load the first page using > > myview?startkey=["201002261927010000"]&limit=2 and use the "next" > document > > retrieved to create the link to the next page. > > > > However, this leaves me with a link to the previous page that is > impossible > > to rewrite to a /date/title type of format. Is there any way to work > around > > this or is this a limitation that has to be lived with? > > > > My last resort would be to create "ugly" links using startkey query > > arguments serverside and then use clientside code to fetch the necessary > > information to change the links to have "prettier" href values. This way > > the > > static html served by couchdb has working navigation and the UI > > improvements > > are happening clientside. > > > > Is there anyway at all to respond to a request for a specific document > (by > > doc._id) or other attribute with the document in question but also the > > previous and next document? > > > > Many thanks, > > Saq > > > --000e0cd13b7ada4c3a0480d623fe--