Bom dia,
estou tentando fazer a conexão com o postgres mas está dando um erro , podem me ajduar ? connectionFactory.js
const { Pool, Client } = require('pg')
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'bancoTeste',
password: 'postgres',
})
pool.query('SELECT NOW()', (err, res) => {
console.log(err, res)
pool.end()
})
const client = new Client({
user: 'postgres',
host: 'localhost',
database: 'bancoTeste',
password: 'postgres',
})
client.connect()
client.query('SELECT NOW()', (err, res) => {
console.log(err, res)
client.end()
})
bancoDados.js
module.exports = function(app){
app.get('/bancoDados',function(req, res) {
console.log('recebida requisicao de teste na porta 3000');
res.send('OK');
});
app.post('/bancoDados/people', function(req, res){
var people = req.body;
console.log('processando uma requisição de um novo pagamento');
people.status = 'CRIADO';
var connection = app.persistencia.connectionFactory();
var peopleDAO = new app.persistencia.PeopleDAO(connection);
peopleDAO.salva(people, function(erro, resultado){
if(erro){
res.send(erro);
}else {
console.log('PAGAMENTO CRIADO');
res.json(people);
}
});
});
}
o erro foi o seguinte :
consign v0.1.6 Initialized in C:\Users\Jessica\node
+ .\controllers\bancoDados.js
+ .\persistencia\connectionFactory.js
+ .\persistencia\PeopleDAO.js
servidor rodando na porta 3000
undefined Result {
command: 'SELECT',
rowCount: 1,
oid: null,
rows: [ { now: 2019-04-12T13:08:29.901Z } ],
fields:
[ Field {
name: 'now',
tableID: 0,
columnID: 0,
dataTypeID: 1184,
dataTypeSize: 8,
dataTypeModifier: -1,
format: 'text' } ],
_parsers: [ [Function: parseDate] ],
RowCtor: null,
rowAsArray: false,
_getTypeParser: [Function: bound ] }
null Result {
command: 'SELECT',
rowCount: 1,
oid: null,
rows: [ { now: 2019-04-12T13:08:29.901Z } ],
fields:
[ Field {
name: 'now',
tableID: 0,
columnID: 0,
dataTypeID: 1184,
dataTypeSize: 8,
dataTypeModifier: -1,
format: 'text' } ],
_parsers: [ [Function: parseDate] ],
RowCtor: null,
rowAsArray: false,
_getTypeParser: [Function: bound ] }
processando uma requisição de um novo pagamento
TypeError: app.persistencia.connectionFactory is not a function
at C:\Users\Jessica\node\controllers\bancoDados.js:15:39
at Layer.handle [as handle_request] (C:\Users\Jessica\node\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Jessica\node\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\Jessica\node\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Jessica\node\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\Jessica\node\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\Jessica\node\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Jessica\node\node_modules\express\lib\router\index.js:275:10)
at C:\Users\Jessica\node\node_modules\body-parser\lib\read.js:130:5
at invokeCallback (C:\Users\Jessica\node\node_modules\raw-body\index.js:224:16)
Podem me dar uma ajuda ? Obrigada