node.js - Calling a Postgres db function in Node API -


i trying call postgres function core.get_age(bigint) in queries.js

function getage(req, res, next){    var customer_id= parseint(req.params.customer_id);    db.one('select * core.get_age($1)', customer_id)      .then(function(data){        res.status(200)          .json({            status: 'success',            data : data,            message: "retrieved age"          });      })  }

any routes in index.js

router.get('/api/age/:customer_id', db.getage);

when call http://localhost:8080/api/age/10 in postman 404 error.

what wrong? first instance trying call postgres function(). trying retrieve postgres table select * from this.this table works function getting 404.

always use .catch promises! point @ problem, invalid number of rows returned in case.

function getage(req, res, next) {   db.func('core.get_age', +req.params.customer_id)     .then(data => {       res.status(200)         .json({           status: 'success',           data : data,           message: "retrieved age"         });     })     .catch(error => {         console.log(error);         next();     }) } 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -