
Show HN: PouchDB - The JavaScript database that syncs - daleharvey
http://pouchdb.com
======
edtechdev
Yeah there's a lot of interesting stuff being developed around pouchdb, I've
been slowly checking it out the past couple of months:

Some beginning tutorials/intros to pouchdb: [http://pouchdb.com/getting-
started.html](http://pouchdb.com/getting-started.html)
[http://briantoth.github.io/Tutorial/2013/03/19/pouchdb-
intro...](http://briantoth.github.io/Tutorial/2013/03/19/pouchdb-
introduction/)
[http://mattgwwalker.wordpress.com/2013/04/08/pouchdb-2/](http://mattgwwalker.wordpress.com/2013/04/08/pouchdb-2/)

Todo Tutorial using AngularJS and PouchDb
[http://twilson63.github.io/ngTodoPouch/](http://twilson63.github.io/ngTodoPouch/)

Building Offline Applications With AngularJS and PouchDB
[http://mircozeiss.com/building-offline-applications-with-
ang...](http://mircozeiss.com/building-offline-applications-with-angularjs-
and-pouchdb/)

Other Apps Using PouchDB [https://github.com/daleharvey/pouchdb/wiki/Who-or-
What-Is-Us...](https://github.com/daleharvey/pouchdb/wiki/Who-or-What-Is-
Using-Pouch)

including this offline conference app
[https://github.com/axemclion/conference](https://github.com/axemclion/conference)

PouchVision - inspect and interact w/pouch instances
[http://brudolph.pouchvision.jit.su/](http://brudolph.pouchvision.jit.su/)

Puton - bookmarklet for inspecting/editing pouch dbs
[http://puton.jit.su/](http://puton.jit.su/)

PeerPouch (PouchDB-over-WebRTC) - in development at one point
[https://github.com/natevw/pouchdb](https://github.com/natevw/pouchdb)

~~~
daleharvey
Thats a great list, gonna add backbone-pouch ([http://jo.github.io/backbone-
pouch/](http://jo.github.io/backbone-pouch/)) to it as well.

Thanks

------
napoleond
I've been keeping an eye on PouchDB for a while; it looks like a lot of fun.
How does authentication with the Couch server work, though? I don't see
anything on the FAQ or after a brief perusal. CouchDB's apparently lax
attitude toward security years ago was what kept me away, but I've always
hoped/assumed that it improved since then. Has it?

~~~
daleharvey
CouchDB had some quirks related to user accounts as it has the added burden of
trying to be an application server as well as a database server.

With PouchDB a lot of the application server logic doesnt apply and you can
use CouchDB as a private data server that requires any connection to be
authenticated, in the example we use basic auth but other methods are
available and none of the security quirks with 'couchapps' apply.

And yes it is a lot of fun :)

~~~
maratd
> With PouchDB a lot of the application server logic doesnt apply

How do I keep one user from accessing another user's data?

~~~
janl
By giving each user their own database :)

~~~
maratd
What will stop one user from accessing another user's database?

~~~
daleharvey
You can configure databases to require the correct user to authenticate before
touching it..

------
daleharvey
I just put up this website, its ugly but working on the content, in particular
I want it very easy to understand wtf it is and get started, would love to
hear your feedback.

~~~
alessioalex
I especially like PouchDB-Server as a mini CouchDB replacement (
[https://github.com/nick-thompson/pouchdb-server](https://github.com/nick-
thompson/pouchdb-server) ). Congrats for implementing LevelDB into PouchDB so
we can use it in Node.

~~~
daleharvey
The congratulations goes to
[https://twitter.com/chesles](https://twitter.com/chesles) who implemented
most of the levelDB adapter and Nick Thompson for the router + server
implementation.

The server is really exciting, we mostly built it so we can reuse CouchDBs
test suite however with it being so easy to install its becoming pretty
invaluable

------
vog
The example code is somewhat weird:

    
    
      var db = new PouchDB('dbname');
      
      db.put({
        _id: 'dave@gmail.com',
        name: 'David',
        age: 66
      });
      
      db.changes({
        onChange: function() {
          console.log('Ch-Ch-Changes');
        }
      });
      
      db.replicate.to('http://example.com/mydb');
    

Shouldn't you set up the event listener before "db.put()"?

~~~
daleharvey
I mostly just wanted to highlight the key features with 'real' code in the
order you would come across them, you are right though might be worth
switching that, thanks

~~~
wodow
You could define two functions to wrap the calls - do_a_put(), do_a_sync() -
in that order and then call them in the reversed order in the example?

------
amitdugar
Is it possible to do something like this for a MySQL (innodb with relational
keys) database ? I am about to begin work on a project that might be used in
countries where we don't have constant connectivity (internet and electricity)
.. and we don't want to lose or corrupt data due to connectivity ...

~~~
daleharvey
I mention this in the FAQ

Can PouchDB sync with MySQL / my current non CouchDB database?

No, the data model of your application has a lot of impact on its ability to
sync, relational data with the existence of transactions make this harder. It
may be possible given some tradeoffs but right now we are focussing on making
PouchDB <-> (PouchDB / CouchDB) sync as reliable and easy to use as possible.

------
abhididdigi
I've been using PouchDB for a month now, and it really is good. Simple, Yet
powerful storage.

------
akrymski
I'm not too familiar with Couch, but as I understand it caches views and
updates them. Does Pouch do something similar, or does the query function
filter all the documents in the database?

~~~
daleharvey
Currently PouchDB views do a full table scan, there is an open bug to do
incremental views more inline with CouchDB -
[https://github.com/daleharvey/pouchdb/issues/99](https://github.com/daleharvey/pouchdb/issues/99)

------
tracker1
I don't understand why they don't shim in using local storage for IE8 and 9?

~~~
daleharvey
Somewhere between IE support not being a hugely requested feature and that the
limitations and speed of localStorage wouldnt make a very useful database. I
think support will likely pop up at some point, it isnt very hard to write a
new adapter, but right now I would rather focus on making it work very well in
modern browsers.

~~~
tracker1
I'm not sure how well localStorage would even work to be honest... as a
key/value store though... prefixing "pouchdb_" \+ KEYNAME as the localstorage
key would probably work. Notifications would probably be the biggest issue, I
don't know pouch very well.

I just know that IE8 will probably be pretty relevant for another 2-3 years or
so, and IE9 for a couple years after that. I don't like it any more than
anyone else, but that's the world we live in.

~~~
daleharvey
Actually we do use localStorage for one thing, they support notifications :)
IndexedDB (nor webSQL) have change notifications so we also do writes to a
localStorage flag to make sure change notifications go through tabs.

------
dschiptsov
a-la Cassandra, but under NodeJS?) I'm Jack's total lack of surprise!))

~~~
daleharvey
Its not really like cassandra, which has functionality aimed towards managing
and querying huge volumes of data. The main feature here is the syncing, which
is reasonably unique to the CouchDB world

------
tmanx
just a simple question, why would you use this instead of, say, php+mysql ?

~~~
daleharvey
My main reason is for web applications that work fully offline and sync their
data to all my devices.

Writing custom code to do that on a mysql stack is very hard.

~~~
BaconJuice
Hi daleharvery quick question, if application is working fully offline, how is
it syncing across all devices?

~~~
daleharvey
It is able to work offline, but if a connection is available it syncs data
(obviously the syncing doesnt work if there is no connection)

~~~
tmanx
so what you're saying is, say you're working on your tablet/mobile/pc with an
intermittent connection, it will continue working and update the db when a
connection becomes available? is this the main benefit compared to the
solution mentioned earlier?

~~~
daleharvey
Close but not quite, PouchDB _is_ the database, you never need to be online to
use it and it isnt queuing writes, its doing them locally.

The ability to sync is to let you use the same data across various devices.

