prisma-extension-create-with-slug
v0.0.5
Published
Prisma Client Extension to automatically generate a unique slug creating a new Database entry.
Downloads
494
Maintainers
Readme
prisma-extension-create-with-slug
Description
Prisma Client Extension to automatically generate a unique slug creating a new Database entry.
Provides a new function that generates a slug depending on a selected field. If needed the field can be unique.
Install
npm install prisma-extension-create-with-slug
Usage
import {createWithSlugFn} from prisma-extension-create-with-slug
const prisma = new PrismaClient().$extends(createWithSlugFn())
const post = await prisma.post.createWithSlug({data:
{
title: "Hello World!",
updatedAt: new Date(),
},
sourceField: "title",
targetField: "slug",
unique: true}
)
Options
await prisma.YOUR_MODEL.createWithSlug({
data: {
...
},
fieldField: 'FIELDNAME' // name of the field you want the slug to be based on
targetField: 'FIELDNAME' // name of the field the slug should be written to
unique: true // whether or not the slug should be unique (increments an integer after the slug)
})
Dependencies
[slugify] (https://github.com/simov/slugify) create with the prisma extension starter