budibase icon indicating copy to clipboard operation
budibase copied to clipboard

Add a flexible built-in generator function for UUIDs

Open noseshimself opened this issue 2 years ago • 7 comments

Describe the feature request Add a built-in facility to generate UUIDs as specified by the application developer permitting to explicitly ask for the sub type (there are applications where you need v1 UUIDs which are varying over time and will be close in value which will be database-friendly and there are cases for v4 (rather random, not good for insertion and SELECT but permit several instances of an application running at the same time)) and for the representation (VARCHAR(36) or rather BINARY(16)). Offer this facility as an option for the creation of primary keys for all databases that support INT of some kind as primary key.

Why Postgres, MySQL and others are obviously offering some built-in functions for generating and handling UUIDs in triggers but they might not be that practical and it is certainly not portable across databases; they might also be limited in their features (e. g. binary representation of UUIDs if they are only used as primary key anyway). In the case of MySQL the best solution currently seems to be writing a stored trigger function for every single table... Madness.

Handling them at the application level seems to be a much cleaner solution here as budibase definitely knows if a new record is generated and needs a newly generated UUID will be required. As the code is running on the server v1 UUIDs will only show variation over time (unless there are multiple servers) and work nearly as well as database server created UUIDs.

noseshimself avatar Aug 21 '22 16:08 noseshimself

@noseshimself try this?


function uuidv4() {
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
  );
}

aderici avatar Aug 21 '22 21:08 aderici

This is part of the work but the result I would like would be the option to change the auto column ID to a database engine agnostic UUID with selectable generator type and presentation as part of the budibase UI. Right now the only option is an auto incrementing integer which is not usable in case you are preparing to have multiple instances of an application or several applications sharing part of their data. My feature request is not just asking for the generator (which I implemented as a MySQL function -- ugh) but including it as basic feature into budibase itself. So even a function uuid (type, packed) would only be a the easiest part of the solution.

noseshimself avatar Aug 21 '22 22:08 noseshimself

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] avatar Oct 22 '22 19:10 stale[bot]

Is there anything new regarding the generation of UUIDs? I'm a bit surprised that Budibase can't generate UUIDs, I think there are many use cases for this.

smart-account avatar Nov 03 '23 15:11 smart-account

bump

A3DataSolutions avatar Nov 06 '23 12:11 A3DataSolutions

using return crypto.randomUUID(); is working for design screens but is not working within automations, why is that so?

smart-account avatar Nov 16 '23 14:11 smart-account

does anyone know why return crypto.randomUUID(); cannot be used in automations?

smart-account avatar Jan 24 '24 12:01 smart-account