当前位置:网站首页>Node. JS accessing PostgreSQL database through ODBC
Node. JS accessing PostgreSQL database through ODBC
2022-07-02 13:24:00 【PegasusYu】
Node.js adopt ODBC visit PostgreSQL database
Node.js In addition to pg Module access PostgreSQL database , You can also use odbc Module access PostgreSQL database . Here are Windows Implementation under the operating system .
install PostgreSQL Of ODBC Support
First install PostgreSQL Of ODBC Support , Can be in ODBC Configure the database import in the configuration tool .
PostgreSQL Of ODBC Support can be downloaded from the official , Download at :https://odbc.postgresql.org
Enter on the download page msi The catalog of 
Find the latest to download 
here X86 The suffix is to 32 The version used by the bit system ,X64 The suffix is to 64 The version used by the bit system , What is not marked is the integration of two versions .
After downloading the compressed package , Just install it directly :
Set up ODBC introduce PostgreSQL database
We need to take what we have PostgreSQL The database is ODBC Configure in the tool , First, find it in the management tool of the control panel ODBC Data source management tools :
Specific options 32 A still 64 Bit data source , Based on PostgreSQL The installed version is 32 A still 64 position ,PostgreSQL Of Windows The version is as follows :
Choose here 64 Bit ODBC The data source tool opens , And carry on PostgreSQL Add database source :
Then configure parameters in the pop-up configuration window :
among :
DataSource yes ODBC The reference name after the database ;
Description Free filling ;
Database It's the database name , That is to say PostgreSQL Management tools pgAdmin A database name in the following location 
SSL Mode Is the safe mode selection , here disable that will do ;
Server It is to fill in the host where the database is located IP Address , It can be used locally 127.0.0.1;
Port It is to fill in the host where the database is located PostgreSQL Service access port ,PostgreSQL The default port during installation is 5432;
User Name Is the user name of database access ;
Password Is the password corresponding to the user name of database access ;
After configuration , You can click on the Test Carry out connection test , Click after success Save Button , To complete the setup . As shown below :
close ODBC Data source configuration tool , In the back Node.js odbc Module installation .
Node.js odbc Module installation
Install well node.js after , In the newly created or selected directory, use the command line odbc Module installation :
npm install odbc
or
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install odbc
Access database
Create... In the project directory js file , Like here. demo.js, Used to read a data table dbtest As well as in a data table DBDEMO Insert a record :
demo.js:
const odbc = require('odbc');
async function myQuery() {
const connectionConfig = {
connectionString: 'DSN=PostgreSQL35W',
connectionTimeout: 10,
loginTimeout: 10,
}
const connection = await odbc.connect(connectionConfig);
const result = await connection.query('SELECT * FROM dbtest');
console.log(JSON.stringify(result));
console.log(JSON.stringify(result));
const result = await connection.query(`INSERT INTO "DBDEMO" ("INDEX", "CODE", "AUTH") VALUES('20220005', 'Insert', 'Test')`);
console.log(JSON.stringify(result));
console.log(JSON.stringify(result));
}
myQuery();
Execute code on the command line :
node demo
give the result as follows :
The red circle is dbtest The contents queried in the data table 
and DBDEMO A record is also inserted into the data table 
That's it node.js adopt odbc Module and connection access PostgreSQL database .
matters needing attention
In the use of Node.js visit PostgreSQL Database time , You need to pay attention to the case of database names and field names and the order of double quotation marks and single quotation marks . For specific analysis and solutions, see : Node.js visit PostgreSQL Precautions and solutions , about Node.js use odbc Module or pg Module access PostgreSQL The problem and solution of database are the same .
–End–
边栏推荐
- 上海交大教授:何援军——包围盒(包容体/包围盒子)
- Download files and preview pictures
- Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
- 【youcans 的图像处理学习课】总目录
- [opencv learning] [image filtering]
- Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud
- D如何检查null
- Jerry's watch time synchronization [chapter]
- SSL证书的分类有哪些?如何选择合适的SSL证书?
- [技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
猜你喜欢

Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
![2022 zero code / low code development white paper [produced by partner cloud] with download](/img/46/92c51090e0c476df3bcffd2d11fb6d.png)
2022 zero code / low code development white paper [produced by partner cloud] with download

Redis database persistence

TVOC, VOC, VOCs gas detection + Solution

挥发性有机物TVOC、VOC、VOCS气体检测+解决方案

Unity SKFramework框架(十六)、Package Manager 开发工具包管理器

Node.js通过ODBC访问PostgreSQL数据库

Unity SKFramework框架(十六)、Package Manager 開發工具包管理器

de4000h存储安装配置

Unity SKFramework框架(二十)、VFX Lab 特效库
随机推荐
Jerry's watch ringtone audition [article]
操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
Jerry's watch reads the alarm clock [chapter]
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Daily question: 1175 Prime permutation
2022零代码/低代码开发白皮书【伙伴云出品】附下载
Explanation of 34 common terms on the Internet
基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】
MAC (MacOS Monterey 12.2 M1) personal use PHP development
题解:《压缩技术》(原版、续集版)
文件的下载与图片的预览
[opencv learning] [Canny edge detection]
免费SSL证书知多少?免费SSL证书和收费SSL证书的区别
研究表明“气味相投”更易成为朋友
Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
上海交大教授:何援军——包围盒(包容体/包围盒子)
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
Japan bet on national luck: Web3.0, anyway, is not the first time to fail!
【youcans 的图像处理学习课】总目录
What are eNB, EPC and PGW?