Planetscale UUID

Can anybody suggest how to use uuid as primary key in planetscale with drizzle orm?
23 Replies
Josh
Josh16mo ago
You have to generate the uuid yourself
Ankan
AnkanOP16mo ago
Also should I use uuid or serial key that's also a question for me
Neto
Neto16mo ago
i dont recomend using uuids they arent sortable in the same way that they were created cuid2 or ulid are two nice alternatives main difference that i can remember is: storage and limit storing string ids are more expensive in terms of storage, but they dont suffer from limitations of length a int id column tops are 4294967295 if you have the scale to worry about topping a column and not wanting to have to deal with changing the schema later, go with string ids if not, just use what you want
Ankan
AnkanOP16mo ago
Actually I was also thinking of going with string ids but was finding a way to auto implment string ids in drizzle I guess I need to do that manually
Neto
Neto16mo ago
you can probably use a default of calling a mysql function
Ankan
AnkanOP16mo ago
is there one for mysql for cuid?
Neto
Neto16mo ago
cuid probably not uuid probably there is one
Ankan
AnkanOP16mo ago
okk then it would be great using an uuid
Neto
Neto16mo ago
check if the mysql server has a generate uuid function
barry
barry16mo ago
Postgres > MySQL t3ggLove
Neto
Neto16mo ago
then you would use this one https://orm.drizzle.team/docs/indexes-constraints#default
import { sql } from "drizzle-orm";
import { int, time, mysqlTable } from "drizzle-orm/mysql-core";

const table = mysqlTable("table", {
int: int("int").default(42),
time: time("time").default(sql`cast("14:06:10" AS TIME)`), // << sql`` calling the function
});
import { sql } from "drizzle-orm";
import { int, time, mysqlTable } from "drizzle-orm/mysql-core";

const table = mysqlTable("table", {
int: int("int").default(42),
time: time("time").default(sql`cast("14:06:10" AS TIME)`), // << sql`` calling the function
});
Ankan
AnkanOP16mo ago
Actually I found PlanetScale to be a nice service but uses mysql behind the scenes. Also Neon has got its own limitations, can you recoomed some hosted service for postgresql? This one we can try out
JacobMGEvans
JacobMGEvans16mo ago
I came here to check to see if this question was moved into here and answered. Awesome to see both happened! Supabase is probably the best postgres hosted service with good DX
barry
barry16mo ago
I like neon too
Neto
Neto16mo ago
if you want a compatible
barry
barry16mo ago
cba with anything mysql
Neto
Neto16mo ago
cockroachdb as well
JacobMGEvans
JacobMGEvans16mo ago
Neon is good, there is a reason Vercel chose it lol
Ankan
AnkanOP16mo ago
I guess moving to Postgresql is kinda the right way. As I was unable to find any direct way in mysql. Thanks guys for the help. It really means a lot to me.
Neto
Neto16mo ago
glad to help
Ankan
AnkanOP16mo ago
Btw one last thing what would you suggest to use Neon or Supabase?
barry
barry16mo ago
neon
Ankan
AnkanOP16mo ago
Okk will go with that👍👍
Want results from more Discord servers?
Add your server