question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I define structure of local IDs?

See original GitHub issue

How could I add prefix or postfix on local ID which was generated automatically before being sent to sync server?

In my case:

  1. every one would register an account on our server, and the identification, with a unique account ID, would be saved in local database after first signing in;
  2. client data would be saved separately into their local database firstly. In my mind, I thought that local IDs would be generated locally and WatermelonDB would try to keep it to be unique locally, right? That means it might not be unique on the remote server.
  3. I would like to prefix or postfix the identification ID to each local ID before sending them to the remote server to avoid the not-unique-remotely issue, and it also could be used for sharding easily on the remote database.

pseudo-code for transforming local ID:

global.identification = {
    id: 12345,
    name: 'myFirstPet'
};
function transformId(item: Model) {
    return global.identification.id + '-' + item._raw_id;
}

But I did not find any comment about postfixing or prefixing on local ID, could you please help me to resolve it?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
radexcommented, Aug 6, 2019

@netbull this was discussed in other issues already. Getting a conflict on a random ID is very, very unlikely. You can absolutely do sync-time ID remapping, but it’s a huge pain in the butt when you have relations between objects.

Hint: you can add this to the documentation somewhere that if the sync pull response returns data with IDs which are integers WatermelonDB uses the random generator, but if they are strings it’s OK.

Indeed, you can add this 😃 You can send a quick PR to the docs from the browser: https://github.com/Nozbe/WatermelonDB/blob/master/docs-master/Advanced/Sync.md

0reactions
stale[bot]commented, Jun 18, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

5.1 Defining Structure Types: struct - Racket Documentation
A struct form with n fields defines up to 4+2n names: struct:id, a structure type descriptor value that represents the structure type.
Read more >
What are Data Structures? - Definition from WhatIs.com
A data structure is a specialized format for organizing, processing, retrieving and storing data. There are several basic and advanced types of data ......
Read more >
Series ID Formats - Bureau of Labor Statistics
Survey Overview The following is a sample format description of the Local Area Unemployment Statistics' series identifier:
Read more >
database - Assigning a local id to a user
A local ID is local to the user but global in the user space, i.e. for every interaction between users the same local...
Read more >
StructureDefinition - FHIR v5.0.0-snapshot3
Multiple keywords may be assigned to the structure. These may either describe the structure, the focus of the structure or both. They are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found