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?
Something like this but instead of mysql and primsa. Have Sqlite and Drizzle
7 Replies
I use nodejs randomuuid:
I dont believe sqlite has uuid generating functionality built in
Hey this is great, thank you. Does this work with expo/react native
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? 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
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
@itsanameidk
This is from the official drizzle docs using cuid package.
I can confirm it works to generate a random id on fromend crud creation and seeding the daabase with data
https://orm.drizzle.team/docs/column-types/sqlite#:~:text=When%20using%20%24default()%20or%20%24defaultFn()%2C%20which%20are%20simply%20different%20aliases%20for%20the%20same%20function%2C%20you%20can%20generate%20defaults%20at%20runtime%20and%20use%20these%20values%20in%20all%20insert%20queries.%20These%20functions%20can%20assist%20you%20in%20utilizing%20various%20implementations%20such%20as%20uuid%2C%20cuid%2C%20cuid2%2C%20and%20many%20more.
SQLite column types - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.