Giter Club home page Giter Club logo

backbone-pouch's Introduction

jo

jo logo

This is jo, a small utility to create JSON objects

$ jo -p name=jo n=17 parser=false
{
    "name": "jo",
    "n": 17,
    "parser": false
}

or arrays

$ seq 1 10 | jo -a
[1,2,3,4,5,6,7,8,9,10]

It has a manual, and you can read why I wrote jo.

Build from Release tarball

To build from a release you will need a C compiler to install from a source tarball which you download from the Releases page.

tar xvzf jo-1.3.tar.gz
cd jo-1.3
autoreconf -i
./configure
make check
make install

Build from Github

Build Status

To install from the repository, you will need a C compiler as well as a relatively recent version of automake and autoconf.

git clone git://github.com/jpmens/jo.git
cd jo
autoreconf -i
./configure
make check
make install

Install

Homebrew

brew install jo

Ubuntu

apt-get install jo

Gentoo

emerge jo

Snap

Thanks to Roger Light, jo is available as a snap package. Use snap install jo from a Linux distro that supports snaps.

Windows

scoop install jo

Others

See also

Credits

backbone-pouch's People

Contributors

andymorris avatar crg-corin avatar jo avatar mattbanister avatar nichoth avatar oliviertassinari avatar scttnlsn avatar squio avatar thriqon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backbone-pouch's Issues

Model With Attachments

Hey there,

Im trying to create a model like this:

var MyModel = Backbone.Model.extend({
idAttribute: '_id',
sync: BackbonePouch.sync({
db: new PouchDB('mydb')
})

defaults:{
...
}
});

but also with attachments support, so i can create a model with some data and a file attached but im not being able to do it :S

Can someone help?

Best Regards,
3nvy

Fetching a single model

I was failing to successfully fetch a single model object. Something like this:

b = new Blob()
b._id = "foo" // foo already exists
b.fetch({
success: function(){
console.log(b)
}
})

What I was finding was that the backbone attributes were not getting filled in properly. On closer examination I found that in the attributes properties was a property named "0" that had the actual attributes I wanted. So I hacked in the if statement below to backbone-pouch.js line 111. And it started working as expected. Is this a bug or am I doing something wrong?

    if (method === 'read') {
      if (response.rows) {
        response = _.map(response.rows, function(row) {
          // use `doc` value if present
          return row.doc ||
            // or use `value` property otherwise
            // and inject id
            _.extend({
              _id: row.id
            }, row.value);
        });
        if (response.length == 1)
          response = response[0]

sync method incompatible with Backbone 0.9.10

I think you need to add add this wrapper for the options.success callback near the top of the (re)definition of sync in backbone-pouchdb.js (taken from the Backbone.sync implementation):

var success = options.success;
options.success = function(resp) {
  if (success) success(model, resp, options);
  model.trigger('sync', model, resp, options);
};

It looks like the signature for the options.success passed to Backbone.sync by Backbone.Collection.fetch changed with 0.9.10. With 0.9.10, it's function(collection, resp, options) and with 0.9.2 it's function(resp, status, xhr).

I'm not sure if doing the fix I suggested would then break compatibility with Backbone 0.9.2 or not.

debugging in Chrome 21

This issue may be with pouchdb rather than backbone-pouchdb.

When I use Chrome-unstable to view the IndexedDB data at http://www.html5rocks.com/en/tutorials/indexeddb/todo/ I see a nice layout, with data text values visible.
When I do the same thing with the pouchdb-todos the data must be stored correctly, because the application works. However, I cannot see the values using the Chrome-unstable debugging tool.

Perhaps this is unavoidable, but in the absence of a Pouch Futon, it would be very useful to be able to see what data is in the db.

.save() removes attributes from model ?

Hey. Thanks for backbone-pouch, everything is very smooth so far :)

I'm porting an application that saves the models on a remote server via Backbone's XHR to PouchDB and backbone-pouchdb. In the current version, save() sends the complete JSON representation to the server and retrieves a complete JSON representation back from the server (I guess that's custom to my application, but I believe that is a nice REST architecture and allows the server to also change the document).

So, in Model.parse, my code (quoting http://backbonejs.org/#changelog 's 1.1.0 section here)

"extract[s] and vivify[s] incoming nested JSON into associated submodels. "

With backbone-pouchdb, however, the data argument for parse is always an object containing just _id and _rev, without the attributes that have just been saved, because of these lines:

response = {
  _id: response.id,
  _rev: response.rev
};

I'd propose to respond with this instead:

response = extend({}, model.toJSON(), {
  _id: response.id,
  _rev: response.rev
});

so the model doesn't think the the server (or PouchDB in this case) deleted all the attributes.

Also, one could argue to only call model.toJSON() once, but I wanted to discuss in general this first before making optimizations.

async fetching Collection is not asynchronous

This:

this.listenTo(entries, 'add', function(entry){ console.log('adding', entry.id) });
entries.fetch({async: false});
console.debug('nrof entries:', entries.models.length);

results in this:

nrof entries: 0
adding <id>
adding <id>
...

Query example using predefined view and startKey / endKey?

Been reviewing the source and having a hard time figuring out how I could set up a Collection to grab it's data from a predefined view with query params.

Essentially I'm looking to do something like this:

class AccountCollection extends Backbone.Collection
  pouch: Backbone.sync.pouch('mydb', {view: 'resources/all', key: 'Account'})

Can you give me an example or point me in the right direction?

Global changes feed

The number of parallel XHR requests is limited in the browser. Having one global changes feed and a dispatcher can solve this issue.

Consolidate API

I am not very happy with the current API because there are three ways to configure the adapter:

  1. in BackbonePouch.sync(options)
  2. in the model: pouch: options
  3. during fetch: fetch(options)

While each is useful, there might be a simpler way to do this without loosing flexibility.
This is related to #27.

On Cordova/PhoneGap: After overriding Backbone.sync, Pouch.replicate will always fail

Hi there. This is a weird one that I don't quite get but after greatly simplifying my code, I've noticed that if I override Backbone.sync using backbone-pouch, any Pouch.replicate after that will fail, even between HTML pages. I've tested on 3 different devices. Has anyone else ran into this?

Here's the error I get like 9 times for every Pouch.replicate.

07-02 07:27:22.309: I/System.out(1514): Storage.executeSql(): Error=constraint failed
07-02 07:27:22.339: E/SQLiteQuery(1514): exception: constraint failed; query: INSERT INTO 'by-sequence' (doc_id_rev, json) VALUES (?, ?);
07-02 07:27:22.339: W/System.err(1514): android.database.sqlite.SQLiteConstraintException: constraint failed
07-02 07:27:22.339: W/System.err(1514): at android.database.sqlite.SQLiteQuery.nativeFillWindow(Native Method)
07-02 07:27:22.339: W/System.err(1514): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:86)
07-02 07:27:22.339: W/System.err(1514): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:164)
07-02 07:27:22.339: W/System.err(1514): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)
07-02 07:27:22.339: W/System.err(1514): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:161)
07-02 07:27:22.339: W/System.err(1514): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:201)
07-02 07:27:22.339: W/System.err(1514): at org.apache.cordova.Storage.processResults(Storage.java:214)
07-02 07:27:22.339: W/System.err(1514): at org.apache.cordova.Storage.executeSql(Storage.java:174)
07-02 07:27:22.339: W/System.err(1514): at org.apache.cordova.Storage.execute(Storage.java:83)
07-02 07:27:22.349: W/System.err(1514): at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:66)
07-02 07:27:22.349: W/System.err(1514): at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
07-02 07:27:22.349: W/System.err(1514): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:51)
07-02 07:27:22.349: W/System.err(1514): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
07-02 07:27:22.349: W/System.err(1514): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
07-02 07:27:22.349: W/System.err(1514): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
07-02 07:27:22.349: W/System.err(1514): at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 07:27:22.349: W/System.err(1514): at android.os.Looper.loop(Looper.java:137)
07-02 07:27:22.349: W/System.err(1514): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:728)
07-02 07:27:22.349: W/System.err(1514): at java.lang.Thread.run(Thread.java:856)

allDocs: include_docs: true is not default per docs

I needed to specify options.allDocs.include_docs: true in order for a collection to actually fetch the document details. That's contrary to my understanding of the docs, which indicate that include_docs should already default to true.

var Todo = Backbone.Model.extend({
  sync: BackbonePouch.sync({
    db: todoDb
  }),
});
Todo.prototype.idAttribute = "_id";
var TodoCollection = Backbone.Collection.extend({
  model: Todo,
  parse: function(result) {
    return _.pluck(result.rows, 'doc');
  },
  sync: BackbonePouch.sync({
    db: todoDb,
    options: {
      allDocs: {
        include_docs: true
        # ^^^^^^^^^^^^^^^^ doesn't include docs without this setting
      }
    }
  })
});
var todos = new TodoCollection();
todos.fetch();

Tighten build system

Current Travis builds take far too long. Think about using a modern pure npm setup without Grunt but with tap tests.

IE + Firefox problems

I'm testing backbone-pouch (todos-sync) locally and I found that there are some problems in IE and Firefox (latest releases):

  • In IE after 2-3 minutes of been inactive, when adding new todos, they are syncing from pouch to couch but not syncing from couch to pouch (if someone else is making changes at the same database).
  • In Firefox when changing from offline to online mode you have to refresh the page in order to sync todos from pouch to couch.

Are these known bugs? Or I have to add something in my configuration?

Persisting multiple Backbone.Collections and their properties

How can I persist/query/update multiple collections in my pouchdb-backbone app? Suppose I want to extend the Todos app so that it can manage multiple Todo lists (each one of them being a Backbone.Collection of Todos).

  • How can I create a view that shows the name of all existing Todo lists in the app? (clicking on the name should open the Todo list).
  • How can I persist Backbone.Collection properties with pouchdb (e.g. author/change date of the Todo list)?

PUT http://localhost:5984/datum_test2/ 412 (Precondition Failed)

Hello Jo,

Thank you for creating this PouchDB adaptor for Backbone apps. Most of it works as I would expect. But when I try to sync my Collection with a CouchDB database that already exists, I get the following error:

PUT http://localhost:5984/datum_test2/ 412 (Precondition Failed)

when I call

app.datumList.pouch(function(err, db) {
     db.replicate.from("http://localhost:5984/datum_test2", {continuous: false});
});

where app.datumList is a Datums collection:

define("datum/Datums", [
    "use!backbone",
    "datum/Datum"
], function(Backbone, Datum) {
    var Datums = Backbone.Collection.extend(
    /** @lends Datums.prototype */
    {
       /**
        * @class A collection of Datums.
        *
        * @extends Backbone.Collection
        * @constructs
        */
       initialize: function() {
       },
       
       model: Datum,
       
       pouch: Backbone.sync.pouch("idb://datum_test")
    });
    
    return Datums;
});

If datum_test2 does not exist on http://localhost:5984 then everything works (i.e. it creates the datum_test2 database on localhost:5984 and fills it with all the items in app.datumList.

I have tried to track down where the "create database" call is being made, but can't figure it out. Do you have any idea?

Thanks!

PS. If you want to see full versions of my code, you can at
https://github.com/trisapeace/Drag-and-Drop-FieldLinguistics/blob/master/public/datum/Datums.js
https://github.com/trisapeace/Drag-and-Drop-FieldLinguistics/blob/master/public/app/AppView.js

Update needed to readme file

The fetchMethod attribute being used for the sync method should just read fetch.

Sorry, can't clone the repository and do a pull request at work!

Jason

Add backbone-pouch to bower

PouchDb itself is available on Bower, and it would be nice to have backbone-pouch added too. This way a Bower based workflow is not broken by adding this dependency. ;)

Documentation of `options`

On section Global Backbone Sync Configuration it must read

var Authors = Backbone.Collection.extend({
  model: Author,
  pouch: {
    options: {
      query: {
        ...
      }
    }
  }
});

instead of

var Authors = Backbone.Collection.extend({
  model: Author,
  pouch: {
    query: {
      ...
    }
  }
});

how to associate collection with instance of model

hi!
first off, thanks for making backbone-pouch!
i'm working on a project with @ahdinosaur that uses it, and we were wondering about some functionality...
basically, we want to be able to associate a collection with a model. the idea is that documents would store the model's id as an attribute, such that the collection would consist only of documents with the correct modelId attribute.
we attempted to do this by dynamically generating a query function to pass to Backbone.Collection.extend as the value for the 'pouch' key.

'makePouch': function (track) {
  return {
  'listen': true,
  'fetch': 'query',
  'options': {
    'query': {
      'include_docs': true,
      'fun': {
        'map': function (doc) {
          if (doc.type === 'clip' && doc.track === track) {
            emit(doc, null);
          }
        },
      },
    },
    'changes': {
      'include_docs': true,
      'filter': function(doc) {
        return doc._deleted || (doc.type === 'clip' && doc.track === track);
      }
    },
  },
};

the idea here is that every instantiation of the Track model has its own collection ClipList.
however, it appears that track is undefined within the query's scope (we confirmed this with if (typeof track === 'undefined') { emit(doc, null); })

this seems like functionality that could/should be supported, but we feel like we aren't approaching this in the right way. do you have any suggestions/pointers?

thanks!

two tabs not in sync

Not sure whether this is an actual issue. I believe so, because the behavior is not consistent with a comparable sample I have seen for backbone-couchdb.

When two tabs are open in the same browser, and both are pointing at the todos index page they are sharing an indexeddb database. However, I would expect _changes feed to refresh the backbone views in real time, but they do not. I need to refresh the browser to see changes made in the other tab.

This is for both todos and todos-sync.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.