Budibase / budibase

Low code platform for building business apps and workflows in minutes. Supports PostgreSQL, MySQL, MariaDB, MSSQL, MongoDB, Rest API, Docker, K8s, and more 🚀
https://budibase.com
Other
21.81k stars 1.5k forks source link

Add a flexible built-in generator function for UUIDs #7391

Open noseshimself opened 2 years ago

noseshimself commented 2 years ago

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.

aderici commented 2 years ago

@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)
  );
}
noseshimself commented 2 years ago

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.

stale[bot] commented 1 year ago

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

smart-account commented 10 months ago

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.

A3DataSolutions commented 10 months ago

bump

smart-account commented 10 months ago

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

smart-account commented 7 months ago

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