Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple 'tables' in PouchDB

Tags:

pouchdb

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.

like image 747
user3.14 Avatar asked Apr 21 '26 08:04

user3.14


1 Answers

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.

like image 56
barbatus Avatar answered May 01 '26 00:05

barbatus