incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex P <apede...@kolosy.com>
Subject Re: Noob Question - Trying to leave SQL behind
Date Tue, 01 Dec 2009 15:55:50 GMT
you don't need any of that with couch. write queue work items as separate
documents. then build a view that just returns all non-started work items:

function (doc) { if doc.started != true emit(null, null); }

then from your code call the view with a limit of 1
(_design/yourdesign/_view/yourview?limit=1) and attempt to save the returned
document with a started flag of true. if someone beat you to it, you'll get
a conflict. if not, you'll save successfuly and do your thing.

hth,
alex.

On Tue, Dec 1, 2009 at 8:31 AM, David Carns <dcarns@gmail.com> wrote:

> I would love to leave SQL behind and migrate to CouchDB.  One of the
> things I have been using SQL for is a rudimentary queuing platform.
> The SQL query that allows this to happen (quite nicely, actually) is:
>
>        update tablename set status = 1 from tablename where id in
> (select top 1 id from tablename where status is null)
>
>        <note>I left out a bunch of NOLOCK arguments and an update to
> another column in the query for better reading</note>
>
> Is there an effective way to do this with CouchDB?  Sorry if this is
> an uninformed question.  A reply of RTFM is fine, but I have not found
> the answer on my own so far.
>
> Thanks in advance.
>
> -David
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message