Skip to content

Commit

Permalink
feat: make updatedAt working when the user update a message and renam…
Browse files Browse the repository at this point in the history
…e the attribute to updatedAt
  • Loading branch information
ixartz committed Sep 1, 2023
1 parent 1218242 commit 4032bc0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "33ba2aeb-9902-4f71-9e40-f18012cd5d31",
"id": "94ce2d74-35a1-4e51-81ba-c9735293e162",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"guestbook": {
Expand Down
4 changes: 2 additions & 2 deletions migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1692483682335,
"tag": "0000_sharp_marten_broadcloak",
"when": 1693571350622,
"tag": "0000_blushing_warhawk",
"breakpoints": true
}
]
Expand Down
7 changes: 5 additions & 2 deletions src/app/api/guestbook/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eq } from 'drizzle-orm';
import { eq, sql } from 'drizzle-orm';
import { NextResponse } from 'next/server';
import { z } from 'zod';

Expand Down Expand Up @@ -34,7 +34,10 @@ export const PUT = async (request: Request) => {

await db
.update(guestbookTable)
.set(body)
.set({
...body,
updatedAt: sql`(strftime('%s', 'now'))`,
})
.where(eq(guestbookTable.id, body.id))
.run();

Expand Down
2 changes: 1 addition & 1 deletion src/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const guestbookTable = sqliteTable('guestbook', {
createdAt: integer('created_at', { mode: 'timestamp' }).default(
sql`(strftime('%s', 'now'))`,
),
updateAt: integer('updated_at', { mode: 'timestamp' }).default(
updatedAt: integer('updated_at', { mode: 'timestamp' }).default(
sql`(strftime('%s', 'now'))`,
),
});

0 comments on commit 4032bc0

Please sign in to comment.