budibase
budibase copied to clipboard
Add a flexible built-in generator function for UUIDs
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 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)
);
}
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.
This issue has been automatically marked as stale because it has not had recent activity.
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.
bump
using return crypto.randomUUID();
is working for design screens but is not working within automations, why is that so?
does anyone know why return crypto.randomUUID();
cannot be used in automations?