neondatabase / serverless

Connect to Neon PostgreSQL from serverless/worker/edge functions
https://www.npmjs.com/package/@neondatabase/serverless
MIT License
318 stars 11 forks source link

Connected to PostgreSQL database error #70

Closed zhongzhuhua closed 3 months ago

zhongzhuhua commented 3 months ago

I used the following code, but it prompted that it could not be linked.

const { neon } = require('@neondatabase/serverless');
const connectionString = 'postgresql://zhong:123456@localhost:5432/mytest';
const db = neon(connectionString);
db.transaction([db('SELECT * FROM example_table')]);

But I am sure that there is no problem with my database. If I use pg, I can connect normally.

const { Client } = require('pg');
const client = new Client({
  user: 'zhong',  
  host: 'localhost',  
  database: 'mytest', 
  password: '123456',  
  port: 5432,  
});
client.query('SELECT * FROM example_table', (err, res) => {
  if (err) {
    console.error('Error executing query:', err);
  } else {
    console.log('Query result:', res.rows);
  }
  client.end();
});

Is there something wrong with my link string? Postgres version 16

jawj commented 3 months ago

It looks like you're trying to connect directly to a local Postgres database?

The neon object represents the https transport option in our serverless driver, and that expects to communicate with Neon's custom proxy service, not directly with Postgres.

zhongzhuhua commented 3 months ago

Thanks, I will try using neon proxy