How to write a good username schema?

I am creating a users table with fields, id, username, email & password. Why do I need to use the id field? Why can't I just use username as the primary key? Would there be any drawbacks to that? If I use primaryKey() then do I need unique().notNull()?
3 Replies
BluePin
BluePin10mo ago
There is a difference in the ability of banks to share information. When you use integer the identification process is 123 to 123. Easy. But for String it is textYash t 2000 results te 1500 tex 100 text 2 results textY 1 result textYash result confirmed. That's not exactly how it does it... But it's an optimized Char dataTypes search algorithm. That's why a string is an "Array[]" of char. So you have to parce each character. an integer is stored in just one memory address. So it is faster to compare. And if you use bigint serial for id and use it with index activated, it will be super quick to find this user. If you have table partitioning logic you can still create user partitions. All this applied will make a super fast search. Furthermore, using unic in primarykey is not necessary. Because no primary key can be repeated, that is, it is already unique and null cannot be inserted in the primary key, so it is necessary to use .notNull. That said, good luck.
{
id: bigserial("id", { mode: "bigint" }).notNull().primaryKey()
}
{
id: bigserial("id", { mode: "bigint" }).notNull().primaryKey()
}
textYash
textYashOP10mo ago
That solves it for me Thanks
BluePin
BluePin10mo ago
You welcome
Want results from more Discord servers?
Add your server