K
Kyselyā€¢11mo ago
EspadaV8

"Correct" way to create a unique index with some raw SQL

I'm attempting to create a new unique index on a username column, but I want it to be unique on LOWER(username). I have the following, and it works, but I was wondering if there is an alternative way to do this without having it all as a raw query?
await sql`CREATE UNIQUE INDEX users_unique_username_idx ON users (LOWER(username));`.execute(
db,
);
await sql`CREATE UNIQUE INDEX users_unique_username_idx ON users (LOWER(username));`.execute(
db,
);
11 Replies
decho
dechoā€¢11mo ago
although im not sure why there is no type-safety here, if i had to take a guess it's by design or im stupid
EspadaV8
EspadaV8OPā€¢11mo ago
Ahhh, expression. I was looking for something like raw or sql. I will give that a go later on tonight. Thank you @decho
decho
dechoā€¢11mo ago
cheers man
EspadaV8
EspadaV8OPā€¢11mo ago
@decho sorry it took a while, just tested it in my code and that works perfectly. Thank you again
decho
dechoā€¢11mo ago
im happy to hear that man and no problem šŸ‘
EspadaV8
EspadaV8OPā€¢11mo ago
hmm, how do I mark this as solved? šŸ˜…
decho
dechoā€¢11mo ago
good question
EspadaV8
EspadaV8OPā€¢11mo ago
ah ha, right click the reply, Apps -> mark as solved
decho
dechoā€¢11mo ago
ah right, you have to right click a comment in this thread yeah
Want results from more Discord servers?
Add your server