the couchapp (better) way

31 views
Skip to first unread message

serapicos

unread,
Oct 12, 2010, 1:43:41 PM10/12/10
to CouchApp
Hi,

i'm reading and trying couchdb and couchapp and i'm willing to build
an application for project tasks work logs, e.g., the app will have a
bunch of users assigned to projects through tasks.
Each users will log their work to the task assigned to him.
The project is created, the project tasks are created and assigned to
an user.
The user will see its tasks and will toogle between them (like play/
pause/stop) creating work logs in the way.
All i want is some suggestions for the couchdb/couchapp better way to
"model" this up:
1. one database for the users (or using the couchdb _users one)
2. one database for projects (and is properties)
3. one database for work logs or one database for each user work logs

Is there a way to connect all the databases in one couchapp? Or should
i do it all in just one database?

Any directions/suggestions will be appreciated!!!

Thanks in advance,
asousa

P. Douglas Reeder

unread,
Oct 14, 2010, 3:32:47 PM10/14/10
to couc...@googlegroups.com
A notable limitation of CouchDB at present is that a user can either read all items in a database or none.  So, if users should not be able to see projects they are not involved in, you'll need a database per project.

There's no need to keep work logs in a different database than projects - that would limit the views you can create.



Sent from my Palm Pre


--
You received this message because you are subscribed to the Google Groups "CouchApp" group.
To post to this group, send email to couc...@googlegroups.com.
To unsubscribe from this group, send email to couchapp+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchapp?hl=en.

Peter Nolan

unread,
Oct 15, 2010, 12:32:24 PM10/15/10
to couc...@googlegroups.com
I got a general question regarding best practices with couchapp and this email seems like a great place to ask it:

regarding individual user  accounts for couchapps: whats the best way to create/save users information such that other apps can have the same user but retain the saved information generated by my couchapp?  because it seems kind of silly to have users keep generating the same account across multiple apps.

Currently im just dumping user profiles saved in the _users database into documents in app design database.  But i feel there should be a better way.

Serpicos: your application sounds like a more amped version of taskr and i would love to help you in the project if you'd like.

--

serapicos

unread,
Oct 15, 2010, 8:42:21 PM10/15/10
to CouchApp
[@Peter Nolan] thanks, any help is appreciated...

my idea is to scaffold a resources with some basic actions/views much
like on Ruby on Rails.
Take the projects resource, it will have index(list), create(new),
show, edit(update) and delete actions/views.
I have been trying (and i am a couchapp newbie:) implement these
actions with Evently, aggregating these actions/views in a so called
couchapp "widget".

I create a widget placeholder in _attachments/index.html

<div id="widget"><div>

and trigger it with

$(#widget).evently("projects", app);

In the app evently folder, i have created the 'projects' event in the
'_init' folder like this
- data.js
function(data) {
return {projects: data.rows};
};
- mustache.html
<ul>
{{#projects}}
<li>{{key}} - {{value}}</li>
{{/projects}}
</ul>

- query.json
{ view: projects }

and i can get the projects list from database.

Now i am struggling to get a link to create a new project within the
primary widget (fire up a form in a new div and maintain the current
list of projects).
Then in each item on the list i planned to install links to edit/
update each project and delete the project (working always from within
the primary widget).

When getting this first widget to work, the same logic could be done
for tasks (or other resources) in each project (maybe in a RESTful
way).

Since i am using this app to study couchDB/couchapp, i am not sure if
this way of building the app is a good one.

Once again, thanks in advance for any help.

On Oct 15, 5:32 pm, Peter Nolan <peterwno...@gmail.com> wrote:
> I got a general question regarding best practices with couchapp and this
> email seems like a great place to ask it:
>
> regarding individual user  accounts for couchapps: whats the best way to
> create/save users information such that other apps can have the same user
> but retain the saved information generated by my couchapp?  because it seems
> kind of silly to have users keep generating the same account across multiple
> apps.
>
> Currently im just dumping user profiles saved in the _users database into
> documents in app design database.  But i feel there should be a better way.
>
> Serpicos: your application sounds like a more amped version of taskr and i
> would love to help you in the project if you'd like.
>
> On Thu, Oct 14, 2010 at 3:32 PM, P. Douglas Reeder <reeder...@gmail.com>wrote:
>
>
>
> > A notable limitation of CouchDB at present is that a user can either read
> > all items in a database or none.  So, if users should not be able to see
> > projects they are not involved in, you'll need a database per project.
>
> > There's no need to keep work logs in a different database than projects -
> > that would limit the views you can create.
>
> > Sent from my Palm Pre
>
> > ------------------------------
> > couchapp+u...@googlegroups.com<couchapp%2Bunsu...@googlegroups.com>.
>
> > For more options, visit this group at
> >http://groups.google.com/group/couchapp?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "CouchApp" group.
> > To post to this group, send email to couc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > couchapp+u...@googlegroups.com<couchapp%2Bunsu...@googlegroups.com>

Peter Nolan

unread,
Oct 15, 2010, 10:07:00 PM10/15/10
to couc...@googlegroups.com
Serapicos meet selectors, selectors please meet serapicos :)

Selectors act like jquery selectors - $(selectors) the selector properties are jquery like selectors.  So #projects would select the div with id projects.  Inside #projects would be more evently code.
Note: be sure that any functions either return something or return false - infinite looping will occur without this.

More info on selectors can be found here:  http://wiki.couchapp.org/page/evently

Now that you know about selectors, lets solve your particular problem:

create a selectors folder inside the _init folder. inside that create a folder called (#projects) inside this folder add your data.js file along with a mustache.html looking like

<li>{{key}}-{{value}}</li>

now also add a text file called render.txt which contains:
"append"

the render variable tells mustache how to render its template - append it to the current? prepend it?  or just replace - which is it's default value.

Then, if you're feeling up to it - you can play with the _changes feed - which will do something automagically on updates to the database. 


Good luck with your code man.  Get on irc - freenode - #Couchapp for more instantaneous help.

-Pete

To unsubscribe from this group, send email to couchapp+u...@googlegroups.com.

Ido Ran

unread,
Oct 17, 2010, 7:06:42 AM10/17/10
to CouchApp
Hi,
I've been trying to learn and use CouchApp lately and I have some
things I don't understand in your design.
Why do you want to keep each peace of data in separate database?
It will make administration and replication that much harder, and one
of the best things I found in CouchDB is ease of use.

CouchDB already has built-in user authentication (who-you-are) and you
can write function for authorization (what-you-can-do). I don't
remember the exact name but it is something like update-function.

By all means I think you should keep your data (documents) in one
database and create views to select different documents.

Ido
> > > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscribe@googlegroups.c om>
> > <couchapp%2Bunsu...@googlegroups.com<couchapp%252Bunsubscribe@googlegro ups.com>
> > >.
>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/couchapp?hl=en.
>
> > > >  --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "CouchApp" group.
> > > > To post to this group, send email to couc...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscribe@googlegroups.c om>
> > <couchapp%2Bunsu...@googlegroups.com<couchapp%252Bunsubscribe@googlegro ups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/couchapp?hl=en.
>
> > > --
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "CouchApp" group.
> > To post to this group, send email to couc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > couchapp+u...@googlegroups.com<couchapp%2Bunsubscribe@googlegroups.c om>

Erdem Agaoglu

unread,
Oct 18, 2010, 3:10:25 AM10/18/10
to CouchApp
Sorry for getting off topic but i have a problem with that render
option. I asked it in here [http://wiki.couchapp.org/page/q-and-a] but
the place seems dead. I'm just copying it. When i use render:'prepend/
append' i can add more listeners to the elements of the newly
prepended/appended element using selectors but not to the prepended/
appended element itself. How can i do this?
> > > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscribe@googlegroups.c om>
> > <couchapp%2Bunsu...@googlegroups.com<couchapp%252Bunsubscribe@googlegro ups.com>
> > >.
>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/couchapp?hl=en.
>
> > > >  --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "CouchApp" group.
> > > > To post to this group, send email to couc...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscribe@googlegroups.c om>
> > <couchapp%2Bunsu...@googlegroups.com<couchapp%252Bunsubscribe@googlegro ups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/couchapp?hl=en.
>
> > > --
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "CouchApp" group.
> > To post to this group, send email to couc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > couchapp+u...@googlegroups.com<couchapp%2Bunsubscribe@googlegroups.c om>

serapicos

unread,
Oct 25, 2010, 10:51:41 AM10/25/10
to CouchApp
[@Ido Ran] at first glance and while reading about couchdb it seems to
me that was a good idea...
I plan to allow users to attach documents and i have read something
about a limit or restriction on
the database file size, so it seems to me that splitting the projects
accross several database files
i could somehow overcome that.
But for now I'll stick with the all in one database file (I'm just a
couchdb/couchapp newbie anyway:).
If I'll need to split it up, I'm sure there will be a way to do that,
right?

So far i managed to list the projects and to create new ones.
Now I'm trying to use the couchdb 'show functions' to edit/update a
project.
I think I could use show function too for creating a new document
(while reading The Definite Guide
it appears to me it could be done that way).
I couldn't manage yet to use that show functions form a evently
widget, for instance, click on a new link
and use a show function with a form and when submit create the project
document, or click on the project name
link and show up a form with the project properties from DB editable
so they could be changed.
I want to click on some other link on a project in the projects list
and start a brand new widget to work on other
project stuff like plan, worklogs, ...

I'll will manage that, with some help from my couch :) (and every one
I hope!!!)

serapicos.
> > > > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscr...@googlegroups.c om>
> > > <couchapp%2Bunsu...@googlegroups.com<couchapp%252Bunsubscribe@googlegro ups.com>
> > > >.
>
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/couchapp?hl=en.
>
> > > > >  --
> > > > > You received this message because you are subscribed to the Google
> > > Groups
> > > > > "CouchApp" group.
> > > > > To post to this group, send email to couc...@googlegroups.com.
> > > > > To unsubscribe from this group, send email to
> > > > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscr...@googlegroups.c om>
> > > <couchapp%2Bunsu...@googlegroups.com<couchapp%252Bunsubscribe@googlegro ups.com>
>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/couchapp?hl=en.
>
> > > > --
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "CouchApp" group.
> > > To post to this group, send email to couc...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > couchapp+u...@googlegroups.com<couchapp%2Bunsubscr...@googlegroups.c om>

J Chris Anderson

unread,
Oct 25, 2010, 11:43:39 AM10/25/10
to couc...@googlegroups.com
On Mon, Oct 25, 2010 at 7:51 AM, serapicos <serapi...@gmail.com> wrote:
> [@Ido Ran] at first glance and while reading about couchdb it seems to
> me that was a good idea...
> I plan to allow users to attach documents and i have read something
> about a limit or restriction on
> the database file size, so it seems to me that splitting the projects
> accross several database files
> i could somehow overcome that.
> But for now I'll stick with the all in one database file (I'm just a
> couchdb/couchapp newbie anyway:).
> If I'll need to split it up, I'm sure there will be a way to do that,
> right?
>
> So far i managed to list the projects and to create new ones.
> Now I'm trying to use the couchdb 'show functions' to edit/update a
> project.
> I think I could use show function too for creating a new document

I find that it is easiest to stick to Ajax functionality when learning
CouchDB / CouchApp. You can consider the advanced show / list / update
stuff as being an upgrade. Eg: I don't use it unless I have a specific
reason I need to serve dynamic HTML (like I want to be crawled by
Google, or I want to render an XML Atom feed or something.)

Chris

> To unsubscribe from this group, send email to couchapp+u...@googlegroups.com.


> For more options, visit this group at http://groups.google.com/group/couchapp?hl=en.
>
>

--
Chris Anderson
jch...@couchone.com
http://jchrisa.net

P. Douglas Reeder

unread,
Oct 25, 2010, 2:45:23 PM10/25/10
to couc...@googlegroups.com
Show functions let you transform a JSON document into something else, such as an HTML page, but are not well adapted to writing modern-style AJAX apps, since you have to update the whole page.

Evently and other widget toolsets allow you transform JSON into _part_ of a page.




Sent from my Palm Pre

To unsubscribe from this group, send email to couchapp+u...@googlegroups.com.

Peter Nolan

unread,
Oct 25, 2010, 6:15:17 PM10/25/10
to couc...@googlegroups.com
Not to hijack this thread (btw im glad there are actual threads being made about couchapp :D)

but can anyone recommend a couchapp that does user information storage/retrieval?  i would like to get some hints/tips on the subject. 

Thanks,

-Pete
--
Peter Nolan
Cell - 631-398-8662
Email - Peter...@gmail.com

J Chris Anderson

unread,
Oct 25, 2010, 7:42:18 PM10/25/10
to couc...@googlegroups.com
On Mon, Oct 25, 2010 at 3:15 PM, Peter Nolan <peter...@gmail.com> wrote:
> Not to hijack this thread (btw im glad there are actual threads being made
> about couchapp :D)
>
> but can anyone recommend a couchapp that does user information
> storage/retrieval?  i would like to get some hints/tips on the subject.
>

Couchappspora

http://github.com/maxogden/couchappspora

http://glitterbacon.couchone.com/couchappspora/_design/couchappspora/index.html

-Chris

--

Reply all
Reply to author
Forward
0 new messages