You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nanoid is just a string at the type level, right? We don't expose a way to create random types at the database level (it would need to be something implemented like the pg extension), but you absolutely can create one in your data layer that inserts objects. Rough sketch:
Making this a generic helper is left as an exercise for the reader 😅 I'd probably just have some function that inserts a nanoid at a default (overridable) key in a source object to abstract out the nanoid insertion. Or really, I'd just do it inline in the places I want them.
It's on our medium-term radar to add some higher level wrappers for doing more generic/abstract things that go beyond just mapping EdgeQL to TypeScript, and we'd probably want to have some similar thing affordance within that context in the future.
It's just that I find Drizzle's option of setting up custom functions from TypeScript incredibly practical, and it helps cleaning up the code quite a bit to setup defaults like that.
I would like to have an extra, short nanoid for one of my tables. How do I do that? Is it possible to do it through the
.esdl
file?On Drizzle, for example, I do something like this:
That's TypeScript, but there are PostgreSQL implementations of it, like viascom/nanoid-postgres.
Anyway, my question is not about nanoid specifically, but about how to do a custom ID.
The text was updated successfully, but these errors were encountered: