当前位置:网站首页>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–
边栏推荐
- Security RememberMe原理分析
- [opencv learning] [Canny edge detection]
- ADB basic commands
- [opencv learning] [contour detection]
- mac(macos Monterey12.2 m1) 个人使用php开发
- Performance optimization of memory function
- Explanation of 34 common terms on the Internet
- JS逆向之行行查data解密
- [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
- Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
猜你喜欢

Embedded software development

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

Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment

Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本

Performance optimization of memory function

Bridge of undirected graph
![[opencv learning] [image histogram and equalization]](/img/e7/b8dc55a9febf2b2949fce3a7ac21f9.jpg)
[opencv learning] [image histogram and equalization]

Unity skframework framework (XIX), POI points of interest / information points
![Lucky numbers in the [leetcode daily question] matrix](/img/c8/47a22644bf8cc1f49c5668d72161b6.jpg)
Lucky numbers in the [leetcode daily question] matrix

Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
随机推荐
Unity SKFramework框架(十二)、Score 计分模块
【笔耕不辍勋章活动】生命不止,写作不息
题解《子数整数》、《欢乐地跳》、《开灯》
机器学习基础(二)——训练集和测试集的划分
Everyone wants to eat a broken buffet. It's almost cold
Three methods of finding LCA of the nearest common ancestor
Embedded software development
Unity skframework framework (XXI), texture filter map resource filtering tool
Post order traversal sequence of 24 binary search tree of sword finger offer
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
Numpy array calculation
[youcans' image processing learning course] general contents
What are eNB, EPC and PGW?
leetcode621. 任务调度器
Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
日本赌国运:Web3.0 ,反正也不是第一次失败了!
Word efficiency guide - word's own template
Research shows that "congenial" is more likely to become friends
Jerry's watch delete alarm clock [chapter]