Is creating multiple PouchDB databases on the same application considered bad design?
Asked Answered
S

1

14

I come from a Mysql background and I'm using Pouchdb now. I'm used to the SQL pattern of having 1 database and many tables per app.

In pouchDB it's different, because data is not stored in tables but in documents. So, in my app, I have a database for tasks, created with:

var db = new PouchDB('tasks', {revs_limit: 1, auto_compaction: true});

This is the main database for my application, but now I need to also store settings, such as "last_visit_date", "language_preference" and others.


So, I have 2 questions:

  1. Should I create only one database and then store different data
    sets in sub objects or can I create multiple databases to store this data Are there any drawbacks on the second option?
  2. I haven't gotten into syncing with cloudant or couchdb yet, but I will have to in the future. If I have 2 databases (or more) will it make the sync process more complicated, slower or worse somehow?
Soothe answered 18/4, 2017 at 4:17 Comment(2)
No, it is NOT bad design, actually it is the way to go with CouchDB.Smaltite
I'm no expert on PouchDb/CouchDb, so if I'm wrong please correct me, but creating a separate DB seems like overkill unless there is a real need for it (as spelled out in example provided in "accepted" answer below). Couldn't you just create different views of your data so as to simulate the existence of different tables in a relational environment?Import
K
21

Is creating multiple PouchDB databases on the same application considered bad design?

In a word: No.

Long answer: Databases in CouchDB/PouchDB are essentially free. And some application designs require multiple databases.

Consider a theoretical Offline-first/mobile app which tracks an agent's sales. It may have a database for inventory management purposes, which is synchronized with a central CouchDB server.

It will likely also have a per-agent database, with client and sales info for a given agent.

The PouchDB app will need both databases. And due to the design of CouchDB, there's no (easy, sane) way to keep those data sets in the same database, and keep agent's records separate from each other.

Databases in CouchDB/PouchDB are more like tables than databases in an RDBMS.

The only real limiting factor for creating additional databases in PouchDB (which doesn't apply to CouchDB), is that there's no easy way to list your existing databases, except with the use of plugin. This needn't be a real limitation--it just means you need to remember which databases you've created (you probably shouldn't be programatically creating randomly-named databases... but that would probably be a bad design anyway. ;-) )

Kellner answered 18/4, 2017 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.