|
I have a very clear goal in mind of trying to make an extension to Prisma to support custom In my case I have a custom ULID function written in P/SQL that generated PostgreSQL UUID-compatible sequential UUIDs, which I would want to define in a Prisma schema as I searched the code base with GitHub Search for hints on how the existing functionality is implemented, but I didn't find any matching source. Thus, my question is: Could you share some pointers on where the native implementation of the Thanks in advance |
Replies: 3 comments 10 replies
|
What exactly are you trying to achieve? The existing Prisma level functions like |
|
Hi there, To keep our discussions organized and focused on the most relevant topics, we’re reviewing and tidying up our backlog. As part of this process, we’re closing discussions that have already been marked as answered but remain open. If this discussion still requires further input or clarification, feel free to reopen it or start a new one with updated details. Your contributions are invaluable to the community, and we’re here to help! For more details about our priorities and vision for the future of Prisma ORM, check out our latest blog post: https://www.prisma.io/blog/prisma-orm-manifesto. Thank you for your understanding and ongoing support of the Prisma community! |
|
Hey everyone, I was actually just reading through the Prisma docs recently, noticed we couldn't pass custom JS functions into Looking at the manual So, I put together a zero-dependency package that parses the DMMF and handles this automatically via schema comments. Just wanted to drop it here for anyone looking for a cleaner setup! Instead of writing massive middlewares, you just do this: 1. Schema: model User {
/// @defaultJs(generateCustomId)
id String @id @default("")
email String @unique
}2. Extension: import { PrismaClient } from '@prisma/client';
import { withJsDefaults } from 'prisma-js-defaults';
// Import the config auto-generated by the package
import { jsDefaultsConfig } from './prisma/generated/js-defaults';
const prisma = new PrismaClient().$extends(
withJsDefaults(jsDefaultsConfig, {
generateCustomId: () => `user_${nanoid()}`
})
);It intercepts all operations (including nested creations) and applies your JS functions out of the box. You can check it out here: |
What exactly are you trying to achieve? The existing Prisma level functions like
uuid()orcuid()are pretty deeply embedded - and actually run on the Query Engine side (and not the database). If you have something that you could store as a Postgres function, you can already use those in as the default by defining them as a string default. Is that what you are looking for?