tags:

views:

99

answers:

3

Hi! I have started to try out noSQL databases now and are currently testing out couchDB. Seems like a good solution, but I really get some headache when I follow available examples on how to create views (queries) to select documents from a database and sort them.

Everything I can find is regarding JavaScript and it would be great to take part of some examples for PHP since that is the language we will use.

So, how do I create views using PHP for couchDB?

+5  A: 

As far as I know, the equivalent of the SQL language that would be used for a relationnal database is, for CouchDB, Javascript.

So, if you want to create some "query", or "view", you have to do it in that language : it's the one that's understood by CouchDb.


PHP and CouchDb are totally independant : the only thing is that :

  • PHP can send requests to CouchDb
  • and get results

But what happens on the CouchDb side is independant of your PHP script -- and there is no PHP on the CouchDb side.


The only way to filter results using PHP would be to :

  • Request more data from CouchDb than you need
  • And throw away, from PHP, what's not needed

But, obviously, that would not be an efficient solution...

Pascal MARTIN
Hi Martin! Once again, thanks for your great answers! Do you know about any PHP libraries then which can help alot to compose the queries in a more mySQL-like way? Maybe a bad idea, but it would be great to shorten the learning curve, I think.
Industrial
You're welcome :-) ;;; sorry, I have no idea about any library that would do that -- and I'm not sure it would be the right approach to the problem : Javascript is quite powerful, and to manipulate an "object-oriented" "database", it is probably a much better tool than SQL, which is a tool made for relational databases... ;;; you're using a tool that's entirely new to you *(even in its basic concepts, I'd guess)* -- it's normal there is some learning curve ;-)
Pascal MARTIN
+1  A: 

I think you need to understand Javascript's stance in CouchDB. Javascript isn't a target language like PHP, Ruby, etc. Javascript is more equivalent to SQL here. The javascript is server-side and CouchDB itself actually executes it. This is what you use to do map/reduce and build views and such.

ryeguy
+1  A: 

Try PHPillow man

Here's a very short introduction to it: http://www.catswhocode.com/blog/getting-started-with-couchdb-tutorial-a-beginners-guide

If you check out the SVN of PHPillow, there's more information in the 'docs' folder

Aaron Mc Adam
Thanks, I will check that out!
Industrial