mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-14 12:14:42 +01:00
Import drizzle replacing prisma
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
16
server/api/article.post.ts
Normal file
16
server/api/article.post.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import {z} from 'zod'
|
||||
|
||||
const PostSchema = z.object({ slug: z.string() }).parse
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { slug } = await readValidatedBody(event, PostSchema)
|
||||
return useDB().insert(tables.posts).values({
|
||||
slug
|
||||
}).onConflictDoUpdate({
|
||||
target: tables.posts.id,
|
||||
set: {
|
||||
views: sql`${tables.posts.views}
|
||||
+ 1`
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user