N
Neon15mo ago
tame-yellow

Don't insert data on database with nextjs

Hello guys this query is working on nextjs? I execute but don't create table :/ and don't display error when i use this Error: relation "short_link_free" does not exist await sql( 'INSERT INTO short_link_free(origin, redirect, created, ip, country, activate) VALUES ($1,$2,$3,$4,$5,$6)', [origin, redirect, created, getIp, getCountry, activate] ) but the table is created PD: i use import { neon } from '@neondatabase/serverless'
No description
No description
4 Replies
fair-rose
fair-rose15mo ago
@Edinson Gutierrez , https://neon.tech/docs/guides/nextjs , Can you refer this ?
Neon
Connect a Next.js application to Neon - Neon Docs
Next.js by Vercel is an open source web development framework that enables React based web applications. This topic describes how to create a Neon project and access it from a Next.js application. To ...
fair-rose
fair-rose15mo ago
And, Try to use Neon AI, If you find yourself facing any errors and even if then it don't get solved then let me know
No description
fair-rose
fair-rose15mo ago
I've already given it your problem statement and this is what it has give me back
import { neon } from '@neondatabase/serverless';

const sql = neon(process.env.DATABASE_URL);

// First, create the table if it doesn't exist
await sql`
CREATE TABLE IF NOT EXISTS short_link_free (
id SERIAL PRIMARY KEY,
origin TEXT,
redirect TEXT,
created TIMESTAMP,
ip TEXT,
country TEXT,
activate BOOLEAN
)
`;

// Then, perform the insert
await sql`
INSERT INTO short_link_free (origin, redirect, created, ip, country, activate)
VALUES (${origin}, ${redirect}, ${created}, ${getIp}, ${getCountry}, ${activate})
`;
import { neon } from '@neondatabase/serverless';

const sql = neon(process.env.DATABASE_URL);

// First, create the table if it doesn't exist
await sql`
CREATE TABLE IF NOT EXISTS short_link_free (
id SERIAL PRIMARY KEY,
origin TEXT,
redirect TEXT,
created TIMESTAMP,
ip TEXT,
country TEXT,
activate BOOLEAN
)
`;

// Then, perform the insert
await sql`
INSERT INTO short_link_free (origin, redirect, created, ip, country, activate)
VALUES (${origin}, ${redirect}, ${created}, ${getIp}, ${getCountry}, ${activate})
`;
Let me know your progress, If you already has solved it
tame-yellow
tame-yellowOP15mo ago
Yes , It has been working fine, what happened was that it points to the development branch that is why the data was not displayed I have a question now, how do I receive the response from the data insertion, for example in mysql it returns the id using neon as it would be.

Did you find this page helpful?