Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.49k stars 589 forks source link

how to change the id format to uuid? #943

Closed osvaldokalvaitir closed 3 years ago

osvaldokalvaitir commented 3 years ago

the id generated by watermelondb looks like 'wypnlx2gbjho3aw4'.

is it possible to change the format of id generation to uuid?

'8e82e350-6e00-11eb-b274-b7302cbbb5f5'

to follow the pattern of my backend!

KrisLau commented 3 years ago

did you ever figure out how to do this?

osvaldokalvaitir commented 3 years ago

@KrisLau

dataCollection.create(data => {
  data._raw.id = uuidv1();
  data.name = 'test';
});

});

KrisLau commented 3 years ago

Thanks!

KrisLau commented 2 years ago

@osvaldokalvaitir I just found a better way to do this! There was apparently a method created called setGenerator and if you call it from the index file you can set all the tables to default to uuid.

setGenerator(() => uuidv4());

alexrififi commented 1 month ago

@osvaldokalvaitir I just found a better way to do this! There was apparently a method created called setGenerator and if you call it from the index file you can set all the tables to default to uuid.

setGenerator(() => uuidv4());

That's exactly it, for everyone. And sometimes a custom generator is required only for some tables