-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressed review comments and more changes
- Loading branch information
Showing
3 changed files
with
31 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
import { NextResponse } from "next/server" | ||
import { Client } from "pg" | ||
import { Pool } from "pg" | ||
|
||
const client = new Client({ | ||
connectionString: process.env.DATABASE_POOLED_URL, | ||
const client = new Pool({ | ||
connectionString: process.env.DATABASE_URL, | ||
}) | ||
|
||
export async function POST(request: Request) { | ||
const body = await request.json() | ||
|
||
try { | ||
await client.connect() | ||
const result = await client.query( | ||
`INSERT INTO items (id) | ||
const result = await client.query( | ||
`INSERT INTO items (id) | ||
VALUES ($1) RETURNING id;`, | ||
[body.uuid] | ||
) | ||
return NextResponse.json({ id: result.rows[0].id }) | ||
} finally { | ||
await client.end() | ||
} | ||
[body.uuid] | ||
) | ||
return NextResponse.json({ id: result.rows[0].id }) | ||
} | ||
|
||
export async function DELETE() { | ||
try { | ||
await client.connect() | ||
await client.query(`DELETE FROM items;`) | ||
} finally { | ||
await client.end() | ||
} | ||
await client.query(`DELETE FROM items;`) | ||
return NextResponse.json(`ok`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters