You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by David Carns <dc...@gmail.com> on 2009/12/01 15:31:21 UTC

Noob Question - Trying to leave SQL behind

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

Re: Noob Question - Trying to leave SQL behind

Posted by David Carns <dc...@gmail.com>.
Thanks a lot.  Much appreciated.

On Tue, Dec 1, 2009 at 10:55 AM, Alex P <ap...@kolosy.com> wrote:
> 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 <dc...@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
>>
>



-- 
David Carns

Re: Noob Question - Trying to leave SQL behind

Posted by Alex P <ap...@kolosy.com>.
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 <dc...@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
>