dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.55k stars 642 forks source link

$$uuid seems not to work #972

Open fsvieira opened 4 years ago

fsvieira commented 4 years ago

Hi, I am trying to follow the sync tutorial/documentation, if I use put with taskID filled it works, but if I don't provide the taskID it gives me the error:

DataError: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.

By using $$, shouldn't be automatically generated a UUID ?

import Dexie from "dexie";

import "dexie-observable";
import "dexie-syncable";

const db = new Dexie("taskroulette");

db.version(1).stores({
    tasks: "$$taskID,createdAt,updatedAt,description,tags,deleted,done",
    // sprints: "createdAt,dueDate,tags",
    //  todo: "taskID,filterTags"
});

async function test() {
    try {

        const id = await db.tasks.put({
            createdAt: Date.now(),
            updatedAt: new Date().toISOString(),
            description: "TODO!!",
            tags: ["1", "2"],
            done: 0
        });

        console.log("Got id " + id);

        const tasks = await db.tasks.where("done").equals(0).toArray();

        console.log(tasks);
    }
    catch (e) {
        console.log(e.toString());
    }

}

test();

export default db;

Thanks.

dfahlander commented 4 years ago

It should. The feature is not very used though. Sometimes nameless imports seem not to perform the side effects they are supposed to (depending on webpack config etc).

So just to nail the issue down further, you could also try if there would be a difference if you'd import the addons into a variable and provide them in the constuctor of Dexie:

import dexieObservable from 'dexie-observable';
import dexieSyncable from 'dexie-syncable';

const db = new Dexie("taskroulette", {addons: [dexieObservable, dexieSyncable]});

If there's a difference, the reason must be something prohibiting the addons from being registered correctly. Package versioning could be a problem here - for example if the addons depend on dexie@2.x and you have dexie@3.x - then the addons may register themeselves on another instance of 'dexie' module. We might need to look into it to deliver addons that accepts dexie@3 if so.

If there's no difference, the feature could be broken in the latest version of the addons/dexie.

What version numbers of the addons and dexie are you using?

fsvieira commented 4 years ago

Hi,

Maybe the problem is that I am not using webpack, I am using parcel.

My versions are:

"dexie": "^2.0.4",
"dexie-observable": "^1.0.0-beta.5",
"dexie-syncable": "^1.0.0-beta.4"

I have been using feature .on("changes", ...) and its working so I think the observable may have registered and syncable two.

I tried your suggestion on the addons and seems to give me the same error on insert.

Next I am going to try to update to dexie@3.x

The feature is not very used though.

So how people are using the sync? Right now I am using something like "&taskID, ..." and then using uuidv4 to generate my ids, I am preparing the application to start developing server side sync code. My problem with this approach is that syncable seems to already have a uuid generator and I didn't want to have duplicated functions.

Thanks, I am loving dexie, thanks for making such cool project.

dfahlander commented 4 years ago

I think it can be wise to continue using your own id generating function so you can control it on both ends. But as we have the feature we should make sure it works as intended. Keeping this issue open.

fsvieira commented 4 years ago

Ok,

I tried to update to dexie 3 using npm and install the current master branch, but got some errors, and I think I would have to update observable and syncable.

So I was unable to test version dexie@3. I can continue with my uuidv4 ids, no problem, so my problem may be solved with that.

What can I do to help? My code is here https://github.com/fsvieira/taskroulette/blob/fv-dexie/src/db/db.js , don't know if it helps, you can see all configurations that I have.

Thanks.

swedenborg commented 4 years ago

Hi, when using example from https://dexie.org/docs/Observable/Dexie.Observable all in html, it works ... $$uuidshows ...

when using a index.html referencing a webpack ./src/observable.js -o dist/bundle.js with same code I get ...

Unhandled rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. transaction@[native code]

thanks

swedenborg commented 4 years ago

without using { addons: [dexieObservable, dexieSyncable] } I get

TypeError: Attempting to change the getter of an unconfigurable property.

and with I get the

Unhandled rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. transaction@[native code]

swedenborg commented 4 years ago

above was on osx:safari when on osx:chrome using { addons: [dexieObservable, dexieSyncable] } brings JOY ... $$uuidworks ...

without on osx:chrome Uncaught TypeError: Cannot redefine property: _localSyncNode

bud-mo commented 4 years ago

I noticed this issues too. For now I am using Dexie.Observable.createUUID() as suggested also here: https://www.bountysource.com/issues/60515733-transactioninactiveerror-if-uuid-is-used-in-angular

Tested with dexie@3.0.1 dexie-observable@1.0.0-beta.7 dexie-syncable@1.0.0-beta.7

dan-developer commented 4 years ago

Still not working?

daniel-seitz commented 1 year ago

I've got the same error.

When you put to the db here, you dont provide a taskId and it shouldnt (I guess) since you want it automatically filled. but you provide a keyPath: tasks: "$$taskID,... which - if I understand the [docs](https://dexie.org/docs/Version/Version.stores()) correctly - would mean that taskID must be present in the object.

I tried with '$$,...' but this unfortunately gives me the same error.

Please correct me if I am wrong.