当前位置:网站首页>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–
边栏推荐
- Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
- OpenAPI generator: simplify the restful API development process
- Node.js通过ODBC访问PostgreSQL数据库
- 二、帧模式 MPLS 操作
- Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
- JS reverse row query data decryption
- Unity SKFramework框架(十六)、Package Manager 开发工具包管理器
- Explanation of 34 common terms on the Internet
- 最近公共祖先LCA的三种求法
- 科技的成就(二十七)
猜你喜欢
完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
最近公共祖先LCA的三种求法
Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
Lucky numbers in the [leetcode daily question] matrix
【笔耕不辍勋章活动】生命不止,写作不息
【云原生数据库】遇到慢SQL该怎么办(上)?
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
Redis database persistence
What are eNB, EPC and PGW?
Unity SKFramework框架(十六)、Package Manager 开发工具包管理器
随机推荐
Web基础
Finally, someone explained the supervised learning clearly
Download files and preview pictures
[opencv] [image gradient]
Jerry's watch stops ringing [article]
Clean up system cache and free memory under Linux
What are the classifications of SSL certificates? How to choose the appropriate SSL certificate?
OpenAPI generator: simplify the restful API development process
三翼鸟两周年:羽翼渐丰,腾飞指日可待
【蓝桥杯选拔赛真题43】Scratch航天飞行 少儿编程scratch蓝桥杯选拔赛真题讲解
[opencv learning] [image pyramid]
挥发性有机物TVOC、VOC、VOCS气体检测+解决方案
SSL证书的分类有哪些?如何选择合适的SSL证书?
Jerry's watch reads the alarm clock [chapter]
[opencv learning] [image filtering]
EasyDSS点播服务分享时间出错如何修改?
Unity SKFramework框架(二十)、VFX Lab 特效库
[opencv learning] [template matching]
二、帧模式 MPLS 操作
【OpenGL】笔记二十九、高级光照(镜面高光)