从哪里开始为Node.js编写Postgres数据访问层?

我正在用Node编写一个Express应用程序,并且想抽象一些我的代码,特别是数据访问的东西。 我想避免只安装一个ORMS,因为我build议不要使用ORM,而应该使用node-postgres本身。

我正在寻找例子,因为我是新来的Javascript。 我会猜想包装在一个对象的东西?

以下是“展示”客户快递资源的一个示例。

exports.show = function(req, res, next) { pg.connect(conString, function(err, client) { client.query('select * from customer where id = ' + req.params.customer, function(err, results) { if (err) { throw next(err.message); } var customer = results.rows[0]; client.query('select * from history where customer_id = ' + req.params.customer + ' order by updated_at desc', function(err, results) { if (err) { throw next(err.message); } var history = results.rows; client.query('select * from contacts where customer_id = ' + req.params.customer, function(err, results) { if (err) { return next(err.message); } var contacts = results.rows; res.render('customers/show', { title: 'Customer ' + customer.name, customer: customer, history: history, contacts: contacts, }); }); }); }); }); }; 

我怎样才能重构这一个很好的DAL?