Generate Random UUID Sqlite

Hey i was wondering how i would create a unique ID that contains a random string of characters for a text?
model User {
id String @id @default(uuid())
}
model User {
id String @id @default(uuid())
}
Something like this but instead of mysql and primsa. Have Sqlite and Drizzle
7 Replies
Revan
Revan13mo ago
I use nodejs randomuuid:
id: text("id", { length: 36 }).primaryKey().$defaultFn(() => randomUUID()),
id: text("id", { length: 36 }).primaryKey().$defaultFn(() => randomUUID()),
I dont believe sqlite has uuid generating functionality built in
Trader Launchpad
Trader Launchpad13mo ago
Hey this is great, thank you. Does this work with expo/react native
itsanameidk
itsanameidkOP13mo ago
when doing drizzle-kit generate:sqlite --out ./drizzle/migrations --breakpoints --schema=./drizzle/schema.ts it should of generated a default in the sql file instead of this right?
CREATE TABLE `applications` (
`id` text(36) PRIMARY KEY NOT NULL,
`name` text NOT NULL
);
CREATE TABLE `applications` (
`id` text(36) PRIMARY KEY NOT NULL,
`name` text NOT NULL
);
Revan
Revan13mo ago
no I would assume no because the randomuuid function is part of the nodejs code, maybe there is a polyfill for node libraries for react native, or react native could have its own cryptography module that you could use
Trader Launchpad
Trader Launchpad13mo ago
I’m trying to figure out a monorepo app with nextjs and expo, utilizing uuid in tables with SQLite. I don’t particularly want to manage 2 separate systems for creating and possibly decoding uuids, hopefully stored in binary format, on nextjs and expo. On MySQL I can use database uuid to standardize, but with SQLite I’m trying to find the best option
Trader Launchpad
Trader Launchpad13mo ago
No description
Want results from more Discord servers?
Add your server