View Full Version : Ext and CouchDB

12 Feb 2011, 4:35 PM
I am not really sure if this is the best place to present this, or if it is even deemd a bug, but there is definitely a data handling issue between CouchDB and JsonWriter. Basically what it comes down to is Ext presents data based on the root id and the defined fields.

ex {"rows" : {"key1" : "value1, "key2" : "value2"}

Since CouchDB manages documents, and not records, it looks for a _rev key/value to ensure there is not a conflict between two people writing to the same doc at a time. The value of this field has to match the current revision id before Couch will update the document.

I have come up with a quick fix to the JsonWriter class that resolves this issue for a single update, but needs some tweaking to support multiple updates to the same record without refreshing the page. I am sure there is a better way to achieve this, but thought I would throw this out there.

Ext.data.JsonWriter = Ext.extend(Ext.data.DataWriter, {

couch : false,

encode : true,

encodeDelete: false,

constructor : function(config){
Ext.data.JsonWriter.superclass.constructor.call(this, config);

render : function(params, baseParams, data) {
if (this.encode === true) {

Ext.apply(params, baseParams);
params[this.meta.root] = Ext.encode(data);
} else {

var jdata = Ext.apply({}, baseParams);
jdata[this.meta.root] = data;
// Add _rev to json array to support CouchDB
if (data._rev && this.couch === true) {
jdata._rev = data._rev;
params.jsonData = jdata;

createRecord : function(rec) {
return this.toHash(rec);

updateRecord : function(rec) {
return this.toHash(rec);

destroyRecord : function(rec){
var data = {};
data[this.meta.idProperty] = rec.id;
return data;
return rec.id;

13 Jul 2011, 11:17 AM

I finally completed a Tutorial series that demonstrates how to use the new MVC pattern and associations classes of ExtJS-4 with CouchDB by means of Peter Muller's software patch. The series includes an introductory write-up, several video screencasts, and some other resources. You can read all about it and view the screencasts here:


I probably made some mistakes and perhaps mis-spoke here and there, so please feel free to offer constructive criticism. You can post comments on my Blog post. My intention is to help both CouchDB users and/or ExtJS-4 users get a jump start with building an MVC client/server CRUD application using document databases as an alternative to relational databases.

Peter Muller created a software patch for ExtJS-4 and Sencha Touch that makes working with de-normalized databases much easier. I find it is a very maintainable solution for me. If Peter's software patch is something that will work for you, please request from Sencha devs that the patch be integrated into an official release of ExtJS-4 and Sencha Touch in the future. The thread is being watched by Ed Spencer, as he is curious to see the demand. To add your voice, get the patch, or report issues, please post a comment in Peter's thread here:


Hope this fills a need... Thanks.