next crud
v4.0.1
next-crud是一个辅助库,它基于Next.js的Prisma模型创建CRUD API路由。
从LIB的版本3开始,我们仅支持Prisma V5及以上。如果您使用的是Prisma V4或以上,请安装LIB的版本2。
该文档可在此处提供
yarn add @premieroctet/next-crud
鉴于以下Prisma模式:
model User {
id Int @id @default(autoincrement())
name String?
email String?
}创建file /pages/api/[...nextcrud].ts.和:
import NextCrud , { PrismaAdapter } from '@premieroctet/next-crud'
import { NextApiRequest , NextApiResponse } from 'next'
const handler = async ( req : NextApiRequest , res : NextApiResponse ) => {
const nextCrudHandler = await NextCrud ( {
adapter : new PrismaAdapter ( {
prismaClient : myPrismaClientInstance ,
} ) ,
} )
return nextCrudHandler ( req , res )
}
export default handler并获取您的全部特色Crud路线!
| 端点 | 描述 | |
|---|---|---|
| 列表 | 获取/api/users | 获取所有用户 |
| 得到 | 获取/api/users/[id] | 获取一个用户 |
| 添加 | 发布/api/users | 创建一个用户 |
| 编辑 | put /api/users/[id] | 更新一个用户 |
| 部分编辑 | 补丁/api/users/[id] | 更新一个用户(部分) |
| 删除 | 删除/api/users/[id] | 删除一个用户 |
您可以运行示例项目以测试您的修改。确保在根文件夹中运行yarn watch 。
该项目是由Premier Octet开发的,Premier Octet是一家专门从事React和React Native Developtments的网络和移动机构。