Open ghost opened 8 years ago
It is the expected behaviour for now, SyncedDB only supports key
as a primary key. If we support arbitrary name for it, we have to identify the name for client and server, then we need a config file or something for that, which makes us confused. See also here.
But I agree that this can cause a migration problem for person like you who wants to use existing data.
Ah, I see. But isn't this rather unflexible?
Would you accept a PR which will still defaults to key
but lets the user specify the key path, if desired? On the other hand, key seems to be a generated "unique" value, which probably has some other function I don't get yet... If key is essential for synceddb, maybe it could be a unique index instead, letting the user choose the key path. Just a few thoughts.
I'll read more into your code and IndexedDB the next few days before attempting any changes. :)
Actually it's @paldepind 's code 😃
Yeah let's do that, it should encourage adoption for such people. I think all we have to do is to make it able to pass keyPath
option to both the client and the backend, edit hardcoded parts, then it should work.
I'll close this, since synceddb doesn't play well with my personal preferences for syncing. Some personal reasons/things that I noticed:
key
is actually a generated unique id; it can't be just an auto incrementing number, because it could collide on the server side (if e. g. both a client A and a client B create different offline versions of an object with key 1
).key
as INT, so the generated key doesn't get stored properly (using varchar should fix the problem).key
, I'd have to heavily change the source code.key
configurable would really mess up the source, because so many functions in utils.js use the key
-property directly. A utils-Factory or sth. like that would be necessary in order the change the name._sdb_
to indicate that a property doesn't belong to the "real" record.key
which must be computed by synceddb and can't be numerical.Thanks for your support and respect for that sophisticated source code!
@whatda That list definitely helps us to think core arch, thanks. As you said offline app should care uniqueness of id in each records (any clustering DB env can also say the same thing in the first place) so auto increment is never be an option.
I still feel configurable keyPath is good for some people so let me keep open it. Also let me change the summary
Hi,
Please read the edit below.
There is a bug which prevents deletion of records from the store:
createTombstone
gets called with the user defined record: https://github.com/paldepind/synceddb/blob/master/client/src/utils.js#L116But it has a hard coded scheme, which expects properties like
key
andversion
: https://github.com/paldepind/synceddb/blob/master/client/src/utils.js#L162So in my stores, my primary key is
id
and notkey
, so when the tombstone gets put into the store, a new record is created (with a new id), which prevents the deletion from being noticed.Possible solution: Pass the primary key field name and its value to createTombstone.
Thank you for your great work!
Edit: I just noticed that a property with name
key
seems to be generated automatically for newly created records. I'm using a db with existing entities, so it doesn't have that.