Help developing a pouchdb adaptor

111 views
Skip to first unread message

Danielo Rodríguez

unread,
May 25, 2015, 2:59:44 AM5/25/15
to tiddly...@googlegroups.com
Hello everyone,

As usual, I want to create a new plugin, but I have some lack of knowledge at certain areas. This one is about where is the best place to instantiate the database object that has to be used. As you probably know, pouchdb is a javascript database you can talk to, but you have to do it through an object. Where is the best place to instantiate that object? Note that you only have to create it once, and talk to it on subsequent save/load operations. I though about creating it in the part of the adapter where it is instantiated, but I'm not sure about this.

Thanks for any hint.

Danielo Rodríguez

unread,
May 25, 2015, 4:57:57 AM5/25/15
to tiddly...@googlegroups.com
Ok,

This is what I have done so far, please let me know if it is correc:

  1.  I added pouch-db as a library module
  2. I have created an startup module that looks like this
    (function(){

    /*jslint node: true, browser: true */
    /*global $tw: false */
    "use strict";

    // Export name and synchronous status
    exports.name = "pouchdb";
    exports.after = ["startup"];
    exports.synchronous = true;

    exports.startup = function() {
        var PouchDB = require("$:/plugins/danielo515/tiddlypouch/pouchdb.js");
        $tw.database = new PouchDB('tiddlywiki');
    };

    })();

I'm thinking about limiting it to browser scope. I know that pouchdb can work both on browser and node, but I'm not sure how to handle this at node side, and how should the plugin behave. Maybe to create two pouch databases (server side and client side) and sync between them?

Andreas Hahn

unread,
May 25, 2015, 6:32:59 AM5/25/15
to tiddly...@googlegroups.com
Hi Danielo,

good to see that you are making progress, I am very interested in seeing this working.
From I can tell, I would start with the browser only and get it to work there, since that seems to be the core use-case of the whole thing. Later though, I can imagine that there probably won't be many changes needed to get it to work with nodejs, since essentially this is how the syncing-pipeline should be:

Browser ---tiddlyweb---> NodeJS server ---PouchDB---> PouchDB server

When you take a look at modules/startup/startup.js (this is where the syncer is initialized), you will see that it is in fact possible to deny a potential PouchDB adaptor to be exectued in the browser, when the TiddlyWeb adaptor is presented (and loaded before your adaptor).
I would not try to create a server and a client side database, as this duplicates existing functionality (remember, the whole nodejs saving thingy does exactly the same) and from what I understand the localStorage in the PouchDB adaptor is only meant for temporary storage with the end goal of syncicng to a CouchDB, right ?
So it makes sense to limit this kind of localStorage to only one of the TW instances involved in a nodejs-setup (which should be the server since that is where all the changes made, come together).

Again though, try not to worry about nodejs just yet, get it working in the browser first.

/Andreas
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/1ef7b7c4-0693-4682-a3f1-0f2dfa8198d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Danielo Rodríguez

unread,
May 25, 2015, 5:55:29 PM5/25/15
to tiddly...@googlegroups.com
Hello Andreas,

I don't understand your diagram at all, but I agree that I want this working on the browser mainly.
My idea is to stick to the single file paradigm as much as possible. In fact I have plans to provide a saver module that downloads the file with the database exported as a Json tiddler,and then load that tiddler to populate the database if it does not exist on the browser. This way you have advantages of both worlds, scalability and portability.

Syncing to a remote database is one of my main goals also.

Andreas Hahn

unread,
May 25, 2015, 6:39:29 PM5/25/15
to tiddly...@googlegroups.com
Hi Danielo,

the diagram basically said: If you run TW in a nodeJS setup, then your
PouchDB sync-adaptor would only run on the node server and not in any
browser instance of TW.


/Andreas

Matabele

unread,
May 26, 2015, 12:05:19 AM5/26/15
to tiddly...@googlegroups.com
Hi Danielo

Have you seen this?


regards

Danielo Rodríguez

unread,
May 26, 2015, 2:07:03 AM5/26/15
to tiddly...@googlegroups.com
Hello Matabelle,

Yes, I am aware of that sync module. In fact I have investigated all the couch-like adaptors. Have you read the necessary steps to make it work? 90% of them are 100% manual and I'm not very satisfied with how it works. I want to provide a more complete solution.

Regards

Matabele

unread,
May 26, 2015, 2:40:04 AM5/26/15
to tiddly...@googlegroups.com
Hi Danielo

I agree -- what is needed is an install that resembles a browser addon/extension: install the addon -- run TW -- and it works!

Another idea would be a facility to sync two running TW's with a browser addon that can push a tiddler (or list of tiddlers) to another instance of TW (much like Pushbullet pushes links.) The Tiddlyclip plugin already does something like this.

regards

Danielo Rodríguez

unread,
May 26, 2015, 5:09:26 AM5/26/15
to tiddly...@googlegroups.com
Hello Matabele


El martes, 26 de mayo de 2015, 8:40:04 (UTC+2), Matabele escribió:

I agree -- what is needed is an install that resembles a browser addon/extension: install the addon -- run TW -- and it works!

There is no need for any addon. PouchDB uses the built in database that modern browsers has. 

 
Another idea would be a facility to sync two running TW's with a browser addon that can push a tiddler (or list of tiddlers) to another instance of TW (much like Pushbullet pushes links.) The Tiddlyclip plugin already does something like this.

Again I don't see the need of an add-on. For syncing several TW we can use a couchdb server (wich is also supported) and make all the TW sync to that server their databases. Sharing individual tiddlers is a totally different feature. It's a nice idea, but will be better to think about it when the project is more mature.
Reply all
Reply to author
Forward
0 new messages