Planetscale UUID

Can anybody suggest how to use uuid as primary key in planetscale with drizzle orm?
23 Replies
Josh
Josh15mo ago
You have to generate the uuid yourself
Ankan
Ankan15mo ago
Also should I use uuid or serial key that's also a question for me
Neto
Neto15mo 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
Ankan15mo 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
Neto15mo ago
you can probably use a default of calling a mysql function
Ankan
Ankan15mo ago
is there one for mysql for cuid?
Neto
Neto15mo ago
cuid probably not uuid probably there is one
Ankan
Ankan15mo ago
okk then it would be great using an uuid
Neto
Neto15mo ago
check if the mysql server has a generate uuid function
barry
barry15mo ago
Postgres > MySQL t3ggLove
Neto
Neto15mo 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
Ankan15mo 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
JacobMGEvans15mo 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
barry15mo ago
I like neon too
Neto
Neto15mo ago
if you want a compatible
barry
barry15mo ago
cba with anything mysql
Neto
Neto15mo ago
cockroachdb as well
JacobMGEvans
JacobMGEvans15mo ago
Neon is good, there is a reason Vercel chose it lol
Ankan
Ankan15mo 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
Neto15mo ago
glad to help
Ankan
Ankan15mo ago
Btw one last thing what would you suggest to use Neon or Supabase?
barry
barry15mo ago
neon
Ankan
Ankan15mo ago
Okk will go with that👍👍
Want results from more Discord servers?
Add your server