couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sho Fukamachi <sho.fukama...@gmail.com>
Subject Re: Newbie: How to create a View
Date Mon, 21 Jul 2008 03:00:54 GMT

On 21/07/2008, at 5:27 AM, Avi Flax wrote:


> While I can now create and "call" a view, I'm still a little confused
> as to the terminology involved and the intended usage patterns.

Yes, it's a very foreign way of thinking if you're coming from SQL- 
land. Expect a few hours of staring blankly at strange-looking  
javascript and thinking "Huh!?". It'll click eventually though : )


> For instance, you used the term "namespace". What might a namespace
> be? Also, the design document includes the key "views" - are there
> other keys supported? Or is that TBD? Also, apparently I can define
> multiple view functions in the "view" key - that's cool, but I don't
> quite understand the intended usage pattern.
>
> For example, how should I name my namespaces and my views?

Well, I think this is completely up to you. You should probably name  
them loosely under their "category". If you look at how some of the  
libraries do it, they name them after the document type they're  
intended to be associated with - for example if you have the doc.type  
"user" you might put any views intended to work on them _view/users.

The "view" key is as far as I know hardcoded and permanent, you're  
free to create as many design documents with whatever _design/names  
you want but that key is necessary.


> Perhaps like this?
>
> http://localhost:5984/vehicles/_view/cars/get_all_cars
> http://localhost:5984/vehicles/_view/cars/get_car
>
> http://localhost:5984/vehicles/_view/trucks/get_all_trucks
> http://localhost:5984/vehicles/_view/trucks/get_truck

Well they seem pretty reasonable to me. However, you could save  
yourself some duplication by defining more than one key in the view  
and having something like this:

http://localhost:5984/vehicles/_view/shared/get_all_of_type
http://localhost:5984/vehicles/_view/shared/get_one_with_type

and then pass the "type" string into it. Obviously that depends how  
you are storing the type etc.


> ...? Or maybe I'm missing the point, perhaps it's intended to be as
> open-ended as it is, so we can make up our own usage patterns.

I think you've hit the nail on the head there!

Sho
Mime
View raw message