pouchdb-community / relational-pouch

Store relational data in PouchDB/CouchDB
Apache License 2.0
405 stars 68 forks source link

Fixed Limit being too large #174

Closed twinkelmann closed 1 month ago

twinkelmann commented 1 month ago

I had a local patch for relational-pouch for a while, that set the limit on requests to 2**32-1 instead of the default very low value.

I was happy to see the recent update 4.1.0 that changed the limit, however the value chosen doesn't work. I had tried it myself without success. And indeed, with the new version of relational-pouch, I am getting the following error on Chrome 128:

TypeError: Failed to execute 'getAll' on 'IDBObjectStore': Value is outside the 'unsigned long' value range.

This PR fixes the issue by setting the limit to 2**32-1 instead of Number.MAX_SAFE_INTEGER, which appears to be the biggest number that works with IDBObjectStore.

I hope this gets merged soon. In the meantime, for anyone encountering this issue, here is how to patch the previous version without too much overhead:

diff --git a/node_modules/relational-pouch/lib/index.js b/node_modules/relational-pouch/lib/index.js
index 50b7872..64262a5 100644
--- a/node_modules/relational-pouch/lib/index.js
+++ b/node_modules/relational-pouch/lib/index.js
@@ -363,7 +363,7 @@ function createRel(db, keysToSchemas, schema) {
         };
         selector['data.' + belongsToKey] = belongsToId;
         //only use opts for return ids or whole doc? returning normal documents is not really good
-        let findRes = await db.find({ selector: selector });
+        let findRes = await db.find({ selector: selector, limit: 2**32-1 });
         return _parseRelDocs(type, foundObjects, findRes.docs);
     }
     function findHasMany(type, belongsToKey, belongsToId) {

I stopped my editor from reformatting the file, however it seems to have created whitespace differences. Sorry about that.