You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Nicolas Steinmetz <ns...@gmail.com> on 2009/06/30 21:56:06 UTC
Creating firsts lists / shows
Hi,
First to introduce myself : New to CouchDB universe, I read the WIP CouchDB
Book, some official documentation and some writings from "benoitc". So now I
try to build my first couchdb app with a simple clone of delicious.
So in a first part, I installed couchapp 0.3.2 and generate a first project
(called "mycouchapp") and then pushed it on my local couchdb server (using
CouchDBX) in a db called "monapp".
At this stage, I got the default placeholder from Couchapp.
Then from Futon, I added 3 documents like this one :
{
"_id": "3b0ce9b06a0f7a110dbd8a72b32f2072",
"_rev": "3-1834349775",
"title": "CouchDB Official site",
"url": "http://couchdb.apache.org/",
"description": "Apache CouchDB is a distributed, fault-tolerant and
schema-free document-oriented database accessible via a RESTful
HTTP/JSON API",
"tag": [
"couchdb",
"database",
"document"
]
}
{
"_id": "63f417d3d2217e4be4d284a30056c84d",
"_rev": "2-1087649587",
"title": "Couchdbkit",
"description": "Couchdbkit goal is to provide a framework for your
Python application to access and manage Couchdb.",
"url": "http://www.couchdbkit.org/",
"tag": [
"couchdb",
"python",
"framework"
]
}
{
"_id": "8fa1e44814d3d1800069127da12e72f9",
"_rev": "2-3730993466",
"title": "couchapp",
"description": "Utilities to make standalone CouchDB application
development simple",
"url": "http://github.com/couchapp/couchapp/tree/master",
"tag": [
"couchdb",
"python",
"ruby"
]
}
I know I should have used better _id but it's my first try and realised it
too late ;-)
I played a little bit with Futon to design some temporary view to try
requests against my documents. All went well.
This done, I would like to create my first lists / shows / views but failed
so far :-(
I tried to build them by looking mainly at sofa code but I always have 404
page with not a lot of info for going further.
I did not forget to push code with couchapp to update my couchdb instance.
My aim was to create two "pages" :
* One list to display all documents
* One show to display a given document
For the list :
* I should have a index.js file in lists directory for the list with a
function like :
function(head, row, req, info) {
// !json templates.index
// !code vendor/couchapp/path.js
// !code vendor/couchapp/date.js
// !code vendor/couchapp/template.js
return respondWith(req, {
html : function() {
if (head) {
return template(templates.index.head, {
assets : assetPath(),
});
} else if (row) {
var fav = row.value;
return template(templates.index.row, {
title : fav.title,
description : fav.description,
url : fav.url
});
} else {
return template(templates.index.tail, {
assets : assetPath(),
});
}
},
})
};
This mean that I have a templates/index/{head|row|tail}.html files. I just
adapted the one of sofa with removing "useless" code in my case
If I understand well, that's all I need with an url like :
http://localhost:5984/monapp/_list/mycouchapp/index/
For displaying a bookmark (fav) :
function(doc, req) {
// !json templates.fav
// !code vendor/couchapp/template.js
// !code vendor/couchapp/path.js
// we only show html
return template(templates.fav, {
title : doc.title,
url : doc.url
description : doc.description,
assets : assetPath(),
});
}
with a fav.html file in /templates/
Url is something like : http://localhost:5984/monapp/_show/mycouchapp/fav/
<_id>
What annoys me is the 404 status for all pages and that from the html
template point of views, I do not see JS that will "talk" to CouchDB
server/instance. There is something "magical" I can't get so far.
As I did not find so far examples from ground/scratch for building lists /
shows, I ask for some help.
Thanks in advance,
Nicolas
PS : On #couchdb, #couchapp, you can find me with the login NiCoS`
PS2 : do not know it it's more a couchapp or couchdb issue - think
it's more couchdb one...
--
Nicolas Steinmetz
http://www.steinmetz.fr - http://nicolas.steinmetz.fr/
Re: Creating firsts lists / shows
Posted by Nicolas Steinmetz <ns...@gmail.com>.
2009/7/1 Nils Breunese <N....@vpro.nl>
> Hello Nicolas,
>
> The wiki has a page on show and list functions that might be helpful:
> http://wiki.apache.org/couchdb/Formatting_with_Show_and_List
Thanks a lot - it helped me achieving to understand the link between views &
lists.
Nicolas
--
Nicolas Steinmetz
http://www.steinmetz.fr - http://nicolas.steinmetz.fr/
RE: Creating firsts lists / shows
Posted by Nils Breunese <N....@vpro.nl>.
Hello Nicolas,
The wiki has a page on show and list functions that might be helpful: http://wiki.apache.org/couchdb/Formatting_with_Show_and_List
Nils Breunese.
________________________________________
Van: news [news@ger.gmane.org] namens Nicolas Steinmetz [nsteinmetz@gmail.com]
Verzonden: dinsdag 30 juni 2009 23:21
Aan: user@couchdb.apache.org
Onderwerp: Re: Creating firsts lists / shows
Benoit Chesneau a écrit :
> This just the urls you user that are wrong. Since I wrote my posts uri
> layhout have changed. I will post something about it tomorrow on my
> web.
With the help of benoitc - I'm nearly 100% achieved :)
Most of my issue was due to the wrong url layout.
It now works well for show and almost for list.
Thanks,
Nicolas
De informatie vervat in deze e-mail en meegezonden bijlagen is uitsluitend bedoeld voor gebruik door de geadresseerde en kan vertrouwelijke informatie bevatten. Openbaarmaking, vermenigvuldiging, verspreiding en/of verstrekking van deze informatie aan derden is voorbehouden aan geadresseerde. De VPRO staat niet in voor de juiste en volledige overbrenging van de inhoud van een verzonden e-mail, noch voor tijdige ontvangst daarvan.
Re: Creating firsts lists / shows
Posted by Nicolas Steinmetz <ns...@gmail.com>.
Benoit Chesneau a écrit :
> This just the urls you user that are wrong. Since I wrote my posts uri
> layhout have changed. I will post something about it tomorrow on my
> web.
With the help of benoitc - I'm nearly 100% achieved :)
Most of my issue was due to the wrong url layout.
It now works well for show and almost for list.
Thanks,
Nicolas
Re: Creating firsts lists / shows
Posted by Benoit Chesneau <bc...@gmail.com>.
2009/6/30 Nicolas Steinmetz <ns...@gmail.com>:
> Hi,
> First to introduce myself : New to CouchDB universe, I read the WIP CouchDB
> Book, some official documentation and some writings from "benoitc". So now I
> try to build my first couchdb app with a simple clone of delicious.
couchapp mailing list could be better for that :
couchapp@googlegroups.com but I will answer here.
>
> So in a first part, I installed couchapp 0.3.2 and generate a first project
> (called "mycouchapp") and then pushed it on my local couchdb server (using
> CouchDBX) in a db called "monapp".
>
> At this stage, I got the default placeholder from Couchapp.
>
> Then from Futon, I added 3 documents like this one :
>
> {
> "_id": "3b0ce9b06a0f7a110dbd8a72b32f2072",
> "_rev": "3-1834349775",
> "title": "CouchDB Official site",
> "url": "http://couchdb.apache.org/",
> "description": "Apache CouchDB is a distributed, fault-tolerant and
> schema-free document-oriented database accessible via a RESTful
> HTTP/JSON API",
> "tag": [
> "couchdb",
> "database",
> "document"
> ]
> }
>
>
> {
> "_id": "63f417d3d2217e4be4d284a30056c84d",
> "_rev": "2-1087649587",
> "title": "Couchdbkit",
> "description": "Couchdbkit goal is to provide a framework for your
> Python application to access and manage Couchdb.",
> "url": "http://www.couchdbkit.org/",
> "tag": [
> "couchdb",
> "python",
> "framework"
> ]
> }
>
>
> {
> "_id": "8fa1e44814d3d1800069127da12e72f9",
> "_rev": "2-3730993466",
> "title": "couchapp",
> "description": "Utilities to make standalone CouchDB application
> development simple",
> "url": "http://github.com/couchapp/couchapp/tree/master",
> "tag": [
> "couchdb",
> "python",
> "ruby"
> ]
> }
>
>
> I know I should have used better _id but it's my first try and realised it
> too late ;-)
>
> I played a little bit with Futon to design some temporary view to try
> requests against my documents. All went well.
>
> This done, I would like to create my first lists / shows / views but failed
> so far :-(
>
> I tried to build them by looking mainly at sofa code but I always have 404
> page with not a lot of info for going further.
>
> I did not forget to push code with couchapp to update my couchdb instance.
>
> My aim was to create two "pages" :
> * One list to display all documents
> * One show to display a given document
>
> For the list :
> * I should have a index.js file in lists directory for the list with a
> function like :
>
> function(head, row, req, info) {
> // !json templates.index
> // !code vendor/couchapp/path.js
> // !code vendor/couchapp/date.js
> // !code vendor/couchapp/template.js
>
> return respondWith(req, {
> html : function() {
> if (head) {
> return template(templates.index.head, {
> assets : assetPath(),
> });
> } else if (row) {
> var fav = row.value;
> return template(templates.index.row, {
> title : fav.title,
> description : fav.description,
> url : fav.url
> });
> } else {
> return template(templates.index.tail, {
> assets : assetPath(),
> });
> }
> },
> })
> };
>
> This mean that I have a templates/index/{head|row|tail}.html files. I just
> adapted the one of sofa with removing "useless" code in my case
>
> If I understand well, that's all I need with an url like :
> http://localhost:5984/monapp/_list/mycouchapp/index/
url is wrong it is on the format :
/yourdb/_design/somedesigndoc/_list/nameoflist/nameofview
> Url is something like : http://localhost:5984/monapp/_show/mycouchapp/fav/
> <_id>
>
again it should be
/yourdb/_design/somedesigndoc/_show/nameofshow/id
> What annoys me is the 404 status for all pages and that from the html
> template point of views, I do not see JS that will "talk" to CouchDB
> server/instance. There is something "magical" I can't get so far.
>
> As I did not find so far examples from ground/scratch for building lists /
> shows, I ask for some help.
>
> Thanks in advance,
> Nicolas
>
> PS : On #couchdb, #couchapp, you can find me with the login NiCoS`
> PS2 : do not know it it's more a couchapp or couchdb issue - think
> it's more couchdb one...
> --
This just the urls you user that are wrong. Since I wrote my posts uri
layhout have changed. I will post something about it tomorrow on my
web.
- benoît