loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
3.86k stars 163 forks source link

Use ULIDs instead of i32s for ID types #641

Open liamwh opened 1 month ago

liamwh commented 1 month ago

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.

kaplanelad commented 1 month ago

You meanin replace the ID type in the models?

jondot commented 1 month ago

@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.

rustdesk commented 1 week ago

ULIDs

uuid v7?