2

I'm new to PouchDB. Now I know how to create DB and how add docs in it. But unlike MySQL, I can't create tables here. One option is to create multiple PouchDBs, which doesn't seem a good idea. I don't want to use CouchDB or something like that.

All I want to use is the localStorage. So say if I have 3 tables in MySQL:

  1. users
  2. messages
  3. positions

How would I structure the databases so that I can efficiently use find (Query by index) to find the data for a particular table? And is it also possible to define column types like we define in MySQL?

There's something explained here, but the accepted answer suggests using CouchDB, which I don't want currently. I think it's possible merely by localStorage.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
user3.14
  • 371
  • 2
  • 15
  • 1
    Highly relevant: https://stackoverflow.com/questions/43463488/is-creating-multiple-pouchdb-databases-on-the-same-application-considered-bad-de – Phonolog Jun 22 '17 at 16:31
  • Okay. I followed this. Now I'm stuck with views part and (I'm trying map/query mentioned here: https://pouchdb.com/api.html#query_database) getting this type of error: https://www.reddit.com/r/CouchDB/comments/420xf1/im_not_to_couchdbpouchdb_and_im_having_a_hard/ – user3.14 Jun 23 '17 at 07:42
  • Possibly it is the path issue. – user3.14 Jun 23 '17 at 07:43

1 Answers1

1

Check out this plugin https://github.com/pouchdb-community/relational-pouch. It does exactly what asked -- creates DB schema with multiple tables. It comes through with certain limitations. For example, there is no a direct way now to use find on types, i.e., you'll need to search for all objects and filter by type:

db.find(selector).then(function (data) {
   return db.rel.parseRelDocs(type, data.docs);
});`

Also, there might be some potential issues with performance if you create deeply nested structures (async relationships might be helpful).

In general, I believe these issues should not be stoppers with smart design or simple schema.

barbatus
  • 244
  • 1
  • 6