triniwiz / nativescript-plugins

Apache License 2.0
80 stars 51 forks source link

[nativescript-couchbase] inBatch method doesn't work on Android #170

Open Bezlepkin opened 1 year ago

Bezlepkin commented 1 year ago

Hi! I try to use the inBatch method, iOS works, but Android doesn't.

      const processingLoop = () => {
        for (let i = 0; i < claims.length; i++) {
          const documentId = 'claim_' + claims[i].id;
          const existingDocument = this.database.getDocument(documentId);
          // add a unique type, since couchbase does not have the name of collections or tables
          Object.assign(claims[i], { _type: 'claim' });

          if (!existingDocument) {
            this.database.createDocument(claims[i], documentId);
          } else {
            this.database.updateDocument(documentId, claims[i]);
          }
        }
      };

      try {
        this.database.inBatch(() => processingLoop());
      } catch (e) {
        console.log('e);
      }

2023-01-31_12-27-53

tartinesKiller commented 1 year ago

I'm having the same issue, and logcat is showing this:

ERROR (app bug): attempt to pass an instance of com.tns.gen.java.lang.Runnable as argument 1 to void com.couchbase.lite.Database.inBatch(com.couchbase.lite.UnitOfWork)
java_vm_ext.cc:594] JNI DETECTED ERROR IN APPLICATION: bad arguments passed to void com.couchbase.lite.Database.inBatch(com.couchbase.lite.UnitOfWork) (see above for details)

I do belive the issue comes from https://github.com/triniwiz/nativescript-plugins/blob/6abf47b2de8a4e26a4c141f950f2012996e95753/packages/nativescript-couchbase/index.android.ts#L33: Couchbase Lite seems to be waiting for a UnitOfWork, but the plugin gives it a Runnable.

I'll try to fix it, but for now, downgrading to 1.3.1 solves this issue. Probably the plugin use a more recent version of Couchbase Lite, but with "old" syntax for this batch operation.

Bezlepkin commented 1 year ago

I solved this by creating a new thread for Android :) for iOS left the implementation offered by the plugin.

agonper commented 1 year ago

Same issue here. Rolling back to 1.3.1 solved the problem.

Bezlepkin commented 1 year ago

I see that there have been updates to make it work on Android. Yay! @triniwiz update the npm please!

KG3RK3N commented 1 year ago

Should be fixed with #180

@triniwiz Please update the npm package.