Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating views with PHP for couchDB

Tags:

php

view

couchdb

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?

like image 204
Industrial Avatar asked Jan 18 '26 08:01

Industrial


2 Answers

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...

like image 87
Pascal MARTIN Avatar answered Jan 20 '26 21:01

Pascal MARTIN


Javascript is privileged as a CouchDB view server only because that's what's bundled with CouchDB. There are view server implementations for many other languages/runtimes, including PHP.

  • JavaScript (CouchDB native)
  • Common Lisp
  • PHP
  • Ruby (fork)
  • Python
    • couchdb-python
    • couchdb-pythonviews
  • Erlang
    • built-in view server
    • erlview
  • Clojure
  • Perl
  • Chicken Scheme
  • Coldfusion
  • Haskell
  • OCaml
like image 22
cemerick Avatar answered Jan 20 '26 21:01

cemerick