Open liamwh opened 1 month ago
You meanin replace the ID type in the models?
@liamwh for the primary table ID, which is used also for constraints, we prefer going the same route as Rails, which is use the simplest type the database offers (int). We definitely encourage people to use UUIDs or some other non-sequential IDs for public identification of entities, but that is up to each individual to make a choice.
So, in other words, you can use Loco generators to work with the models, and you'll get a sequential ID for working with relations ands such. This ID is typically hidden in APIs and only used internally for the benefit of developer experience (and in some degree for giving DBs less hard work with constraints).
And then you can use an opaque kind of ID like ULID or UUID for public handling of entities as well and in addition. We found that this formula is the best of both worlds: simplicity and safety.
I hope that can fulfill your requirement. If you have any reason not to work that way we'll be happy to hear and see what we can learn from it.
ULIDs are the best ID type. It would modernise loco to use them instead of i32s. The is a crate to be able to use them here.