Skip to content

Commit

Permalink
feat: remove notnull in schema.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Aug 19, 2023
1 parent 5a3e66c commit 10f4943
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions api.http
@@ -0,0 +1 @@
POST http://localhost:3000/api/guestbook/add
4 changes: 4 additions & 0 deletions drizzle.config.ts
Expand Up @@ -3,4 +3,8 @@ import type { Config } from 'drizzle-kit';
export default {
out: './migrations',
schema: './src/models/schema.ts',
driver: 'libsql',
dbCredentials: {
url: 'http://127.0.0.1:8080',
},
} satisfies Config;
@@ -1,7 +1,7 @@
CREATE TABLE `guestbook` (
`id` integer PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`body` text NOT NULL,
`email` text,
`body` text,
`created_at` integer DEFAULT (strftime('%s', 'now')),
`updated_at` integer DEFAULT (strftime('%s', 'now'))
);
6 changes: 3 additions & 3 deletions migrations/meta/0000_snapshot.json
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "2c0ef5a2-66f5-48e4-99f6-b3eca322c507",
"id": "c55aece1-11e9-4c82-9457-bce886c9e3f9",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"guestbook": {
Expand All @@ -18,14 +18,14 @@
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"autoincrement": false
},
"body": {
"name": "body",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"autoincrement": false
},
"created_at": {
Expand Down
4 changes: 2 additions & 2 deletions migrations/meta/_journal.json
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1692396438758,
"tag": "0000_curvy_spacker_dave",
"when": 1692480169696,
"tag": "0000_new_prowler",
"breakpoints": true
}
]
Expand Down
5 changes: 1 addition & 4 deletions src/app/api/guestbook/add/route.ts
Expand Up @@ -12,8 +12,5 @@ export const POST = async () => {
})
.run();

const guestbook = await db.select().from(guestbookTable).all();
console.log(guestbook);

return NextResponse.json({ hello: 'world' });
return NextResponse.json({ success: true });
};
24 changes: 24 additions & 0 deletions src/app/guestbook/page.tsx
@@ -0,0 +1,24 @@
import type { Metadata } from 'next';

import { db } from '@/lib/db';
import { guestbookTable } from '@/models/schema';
import { Main } from '@/templates/Main';

export const metadata: Metadata = {
title: 'Guestbook',
description: 'An example of CRUD operation',
};

const Guestbook = async () => {
const guestbook = await db.select().from(guestbookTable).all();

return (
<Main>
{guestbook.map((elt) => (
<div key={elt.id}>{elt.body}</div>
))}
</Main>
);
};

export default Guestbook;
4 changes: 2 additions & 2 deletions src/models/schema.ts
Expand Up @@ -3,8 +3,8 @@ import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const guestbookTable = sqliteTable('guestbook', {
id: integer('id').primaryKey(),
email: text('email').notNull(),
body: text('body').notNull(),
email: text('email'),
body: text('body'),
createdAt: integer('created_at', { mode: 'timestamp' }).default(
sql`(strftime('%s', 'now'))`,
),
Expand Down

0 comments on commit 10f4943

Please sign in to comment.