2011-06-24 21 views
5
Ben node.js bir Postgres bağlanmaya çalışıyorum

node.js, ama her zaman bazı garip hatapostgres bağlantı sorunu

ENOTFOUND, Domain name not found 

Ben pg 'olduğunu kullanmak node.js modülü olsun .

pg://, tcp:// and postgres:// 

Eğer bir doğru olan lütfen bana:

kaç örneklerde farklı bağlantı dizeleri gördü? Ve bu soruna neden olan nedir?

+0

Kodunuzu gönderir misiniz? – Kuberchaun

cevap

9

Burada, PG veritabanımı bir web arabirimi vermeye çalıştığım bir kod. Curl veya bir web tarayıcısı üzerinden gönderdiğiniz komutlara bağlı olarak kayıtları bağlayıp/silebilir/seçebilir.

var app = require('express').createServer(); 
var pg = require('pg'); 
var conString = "postgres://YOURUSER:[email protected]/dev"; 

var client = new pg.Client(conString); 
client.connect(); 

app.get('/', function(req, res){ 
    res.send('hello world'); 
}); 

app.get('/select/:client_id', function(req, res){ 
    var query = client.query("select '{count:}' as c_count,client_id from test_input where client_id = $1 limit 1", [req.params.client_id]); 
    query.on('row', function(row) { 
    res.send(row); 
}); 
} 
); 

app.get('/insert/:client_id', 

function(req, res) 
{ 

    console.log('called'); 
    client.query("INSERT INTO test_input(client_id) VALUES($1)",[req.params.client_id]); 
    res.send('done'); 
}); 


process.on('uncaughtException', function (err) { 
    console.log(err); 
}); 


app.get('/delete/:client_id', 

function(req, res) 
{ 

    console.log('called'); 
    client.query("DELETE FROM test_input WHERE client_id = $1",[req.params.client_id]); 
    res.send('done'); 
});