Skip to content

Commit 78fde92

Browse files
Refactor SQL query syntax in user image and comments table creation
- Updated SQL query syntax to use template literals for better readability and consistency. - Changed method calls from `sql()` to `sql.query()` for inserting data into the database.
1 parent 5132dcf commit 78fde92

File tree

2 files changed

+4
-4
lines changed
  • with-nextjs-aws-s3/app/api/user/image
  • with-nextjs-server-actions/app

2 files changed

+4
-4
lines changed

with-nextjs-aws-s3/app/api/user/image/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export async function POST(request: NextRequest) {
77
const sql = neon(process.env.DATABASE_URL);
88
try {
99
// Create the user table if it does not exist
10-
await sql('CREATE TABLE IF NOT EXISTS "user" (name TEXT, image TEXT)');
10+
await sql`CREATE TABLE IF NOT EXISTS "user" (name TEXT, image TEXT)`;
1111
// Mock call to get the user
1212
const user = "rishi"; // getUser();
1313
// Insert the user name and the reference to the image into the user table
14-
await sql('INSERT INTO "user" (name, image) VALUES ($1, $2)', [
14+
await sql.query('INSERT INTO "user" (name, image) VALUES ($1, $2)', [
1515
user,
1616
objectUrl,
1717
]);

with-nextjs-server-actions/app/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export default function Page() {
66
// Create an instance of Neon's TS/JS driver
77
const sql = neon(`${process.env.DATABASE_URL}`);
88
// Create the comments table if it does not exist
9-
await sql("CREATE TABLE IF NOT EXISTS comments (comment TEXT)");
9+
await sql`CREATE TABLE IF NOT EXISTS comments (comment TEXT)`;
1010
const comment = formData.get("comment");
1111
// Insert the comment from the form into the Postgres (powered by Neon)
12-
await sql("INSERT INTO comments (comment) VALUES ($1)", [comment]);
12+
await sql.query("INSERT INTO comments (comment) VALUES ($1)", [comment]);
1313
}
1414
return (
1515
<form

0 commit comments

Comments
 (0)