Thank you so much for this library! It saved me from an insane deadline (for a few days anyway). I know very little about javascript (and knew nothing about backbone two months ago) and I can't tell you how much this backbone-websql helped me!
This isn't so much an issue, but more the fact that I have no idea how to contact the person responsible for writing and maintaining backbone-websql.
I wrote an app that used Backbone to communicate with a Web Service. This was based on a template Web Service client generated by NetBeans.
Then I had the need for offline mode that would store the values locally as well, so I had to make some changes to how the id is used so that there would be minimal difference between working offline and online.
The end result is that your model has a 'urlRoot' and the 'store' attributes.
var buildingStore = new WebSQLStore(app.db, "building");
models.Building = models.LocalRemoteModel.extend({
urlRoot: app.urlBase + "entity.building/",
store: buildingStore,
idAttribute: 'buildingSeq',
defaults: {
buildingName: "",
buildingAddress: ""
},
toViewJson: function() {
var result = this.toJSON(); // displayName property is used to render item in a list
result.displayName = this.get('buildingName');
return result;
}
});
models.BuildingCollection = models.LocalRemoteCollection.extend({
model: models.Building,
store: buildingStore,
url: app.urlBase + "entity.building/"
});
var shopStore = new WebSQLStore(app.db, "shops", [{name: 'fkeyBuildingSeq', type: 'number'}]); //f add column names
Other than that I wrote a base Model and Collection that looks at a setting to decide whether it's a local call or a remote one and then calls Backbone.sync for local or Backbone.originalSync for remote. For remote calls I wrap the parameters in $.param(options.data); so that the parameters in the fetch call can be normal javascript.
if (app.alwaysUseRemote == true || options.remoteSync) {
//f if remote and there are parameters, use $.param() here, so we can get json object notation for local storage
if (options.data) {
options.data = $.param(options.data);
}
result = Backbone.originalSync(method, model, _.extend(options, errorHandler));
} else {
//f use the options.data to get the params: someFkey=1 param2=Value2
if (options.data) {
options.filters = options.data; //f for query search
}
result = Backbone.sync(method, model, _.extend(options, errorHandler));
}
I also changed it so that you could have a column that represents a field of an embedded entity, like a Customer Model could have a field for membership.seqNo (which I reference like membership$seqNo inside backbone-websql). This makes searching for data simpler.
A filtered fetch that works for both web service and local query:
var shopCollection = new models.ShopCollection();
shopCollection.fetch({
data: {fkeyBuildingSeq: parseInt($('#building').val())}, //f uses query param.
success: function() {
//f do something with the collection of shops that are linked to this building
}
});
I also changed the isSingleResult to check if the fetch call was made from a collection or a single Model, which is now consistent with what would happen when querying the web service.
I changed the parameters for the success/error callbacks of the sync method to work with backbone 0.9.10.
Then I added automatic schema migration for when you change your model to include extra columns (or remove them). It will now recreate those tables with the new columns populated from the javascript object in the value column.
I don't know if anyone else would like to use these features, but it seems like a nice fit: read data remotely and store locally (or vice versa) by only changing one parameter between fetch and save. Other sections of your site don't even need to know if the data is local or remote.
I'd like to contribute my changes, but don't know who to send them to for review.