CouchDB API as Angular.JS (native) module and service

1,850 views
Skip to first unread message

eddelplus

unread,
Dec 19, 2012, 4:29:16 PM12/19/12
to ang...@googlegroups.com
Hi,

Like most noobs with AngularJS I'm solidly impressed by it. So much so that I started my first little open source project at age 46.
So far the gold-standard for browser JavaScript talking to a CouchDB backend is the jquery.couch.js plugin that's part of every
CouchDB installation, supporting the Futon admin web application.

Just as that library relies heavily on jQuery's $.ajax(), I've based my library on angular's $http, after figuring out that $resource and CouchDB
do not provide a harmonious match, with some RESTless stuff in the CouchDB http API.

Here is the project. There's a sample application out there and a few Wiki pages of documentation:

CornerCouch on GitHub

As seen on this guy's GitHub the jquery.couch.js library can be integrated into an AngularJS app just as easily. I'd welcome some feedback, whether anyone
thinks it is a worthwhile venture to go the AngularJS only path, other than for avoiding a couple of $apply calls. A striking benefit of $http over
$.ajax certainly is the opportunity to chain several success or error handlers to the call, with $http returning a $q promise.

Angular.JS will be a shining star no matter what. CouchDB might need a shot in the arm after CouchBase went another route. Angular.JS could be the library to really make CouchApp
development a more popular approach.

Cheers
Jochen

Pawel Kozlowski

unread,
Dec 19, 2012, 5:21:56 PM12/19/12
to ang...@googlegroups.com
Hi!

Interesting, I wanted to write a similar thing for a while as I'm
maintaining a similar wrapper for MongoDB:
https://github.com/pkozlowski-opensource/angularjs-mongolab-promise

For me it definitively makes sense to go AngularJS - native way. Not
only it avoid apply but also cuts down number of bytes.
What I would suggest though is to shape the API to follow the
$resource one 0 something people are used to.

But yeh, AngularJS-native approach is the way to go for me.

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

eddelplus

unread,
Dec 19, 2012, 5:39:08 PM12/19/12
to ang...@googlegroups.com
Hi Pawel,

I did take a look at $resource before starting out. I could never have come up with that kind of JS Ninja artistry myself, wrapping the instance level constructor in a resource level closure. Definitely the way to go. The resource level is my CouchDB level and the instance level is the CouchDoc. Core methods follow the naming convention (save, remove, query).

Jochen

Peter Bacon Darwin

unread,
Dec 19, 2012, 6:15:25 PM12/19/12
to ang...@googlegroups.com
This is cool.  It would be even cooler if you could write a load of unit tests for it!
Pete




Jochen

--

mlegenhausen

unread,
Dec 20, 2012, 10:01:51 AM12/20/12
to ang...@googlegroups.com
Maybe you want to combine ist with http://pouchdb.com/ so you can create a total offline app that sync automatically.

nirmal patel

unread,
Nov 6, 2014, 8:51:34 AM11/6/14
to ang...@googlegroups.com
hi ,

i am developing a demo with your reference available in git.
but i have a problem in my demo

I am trying to retriew datafrom couchDb.
For that i am using $http of angular js and it works.
Now i want to use jquery.couch.js to just retriew data.
I got data in response and I am assigning it to $scope.model name

myapp.controller("myController",function($scope){
$.couch.db("test").view("fview/getDetails",{
   success: function(response) {
console.log(response);
$scope.modelname = response.rows; 
   },
   error: function(status) {
       console.log(status);
   },
   reduce: false
});

  });
});


my console also showing the response.

{"total_rows":1,"offset":0,"rows":[{"id":"0ce945c50e2036ff2bcd124f8a000009","key":1,"value":{"sname":"Nikita","sbranch":"MIT","ssemester":4,"spercentage":62}}]}


In my html i am using ng-repeat for modelname

<tr ng-repeat="x in modelname"> 
<td>{{x.key}}</td>
<td>{{x.value.sname}}</td>
<td>{{x.value.sbranch}}</td>
<td>{{x.value.ssemester}}</td>
<td>{{x.value.spercentage}}</td>
</tr>


But I am getting nothing in table row.also firebug not showing any errors.

Please help me with this.
Reply all
Reply to author
Forward
0 new messages