node.js中的数据库查询(php风格)

时间:2013-06-29 01:37:19

标签: javascript database node.js socket.io postgis

我终于明白了websockets的概念。我在这里找到了很棒的Q / As,帮了很多忙,谢谢。我将安装node.js与apache和geoserver一起用于web映射项目,我将使用node.js来处理websockets。在实践中,编码方面,我对PHP更有经验,而且我很难将我的逻辑从传统的xml-http请求中移除,但我会给它一个镜头。

在我深入研究之前的一些问题。我使用postgreSQL / postGIS,如何从node.js执行数据库查询到postgreSQL / postGIS?我已经习惯了传统的PHP查询,如下所示

 $stmt = $dbh->prepare("SELECT pins.p_name FROM     pins
 WHERE type.t_id=pins.p_type AND
    AND p_id = :nm");
$stmt->bindParam(':nm', $nm, PDO::PARAM_STR);
$nm=$jas;
$data=array('nm'=>$nm);
$stmt->execute($data);
//blah blah
//(I always use PDO and prepared statements)

大多数教程都在谈论聊天应用程序,但是查询和与postgreSQL / postGIS通信呢?在node.js / socket.io中可以吗?任何提示/教程?我想执行查询,收集结果,放置一些html标签,然后将其推回到客户端,在特定的div中。

另外,node.js现在正在使用Windows 7,没有问题吗?在过去它没有,但我想现在确实如此,因为他们有一个msi安装程序。正确?

非常感谢...

1 个答案:

答案 0 :(得分:1)

使用节点Postgres https://github.com/brianc/node-postgres/  该文档非常好且易于使用。

它还允许使用格式为

的预准备语句
query( {name:"emp_name", text:"select name from emp where emp_id=$1", values:[123]} )