Nodejs连接PostgreSQL
发布时间:2020-12-13 16:55:06 所属栏目:百科 来源:网络整理
导读:Nodejs连接PostgreSQL 1.PostgreSQL介绍 (1)官网 https://www.postgresql.org/ (2)安装 下载安装版的,windows下傻瓜安装。。。 (3)数据库管理器 Navicat for PostgreSQL QQ截图20170521193014.jpg 2.Nodejs连接PostgreSQL数据库 (1)使用pg包 https:
Nodejs连接PostgreSQL1.PostgreSQL介绍(1)官网 2.Nodejs连接PostgreSQL数据库(1)使用pg包 var pg = require('pg'); //数据库配置 var conString = "tcp://postgres:root@localhost/nodejspg"; //tcp://用户名:密码@localhost/数据库名 var client = new pg.Client(conString); (4)连接和配置数据库 var tem = 33; //sql语句 selectSQLString = 'insert into pet(tem) values ('+tem+') '; //客户端连接,进行数据插入 client.connect(function(error,results){ if (error) { console.log('clientConnectionReady Error:'+error.message); client.end(); return; } console.log('connection success...n'); client.query(selectSQLString,function(error,results){ console.log(error); }) }); (5)数据库时间自动填充
alter table pet add column time timestamp without time zone not null default localtimestamp(0); @治电小白菜20170521 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |