当前位置:网站首页>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–
边栏推荐
- 题解:《你的飞碟在这儿》、《哥德巴赫猜想》
- Clean up system cache and free memory under Linux
- Professor of Shanghai Jiaotong University: he Yuanjun - bounding box (containment / bounding box)
- [opencv learning] [image filtering]
- 2022零代码/低代码开发白皮书【伙伴云出品】附下载
- D如何检查null
- 三翼鸟两周年:羽翼渐丰,腾飞指日可待
- 诚邀青年创作者,一起在元宇宙里与投资人、创业者交流人生如何做选择……...
- [opencv learning] [Canny edge detection]
- 嵌入式软件开发
猜你喜欢
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
OpenAPI generator: simplify the restful API development process
Unity skframework framework (XX), VFX lab special effects library
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
VIM super practical guide collection of this one is enough
上海交大教授:何援军——包围盒(包容体/包围盒子)
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Ali on three sides, it's really difficult to successfully get the offer rated P7
随机推荐
科技的成就(二十七)
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Partner cloud form strong upgrade! Pro version, more extraordinary!
Jerry's watch gets the default ringtone selection list [article]
Jerry's watch time synchronization [chapter]
Record idea shortcut keys
Unity SKFramework框架(十九)、POI 兴趣点/信息点
Download files and preview pictures
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
VIM super practical guide collection of this one is enough
2022 zero code / low code development white paper [produced by partner cloud] with download
Finally, someone explained the supervised learning clearly
moon
[youcans' image processing learning course] general contents
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
What are eNB, EPC and PGW?
无向图的桥
Web基础
Lucky numbers in the [leetcode daily question] matrix
Unity SKFramework框架(十三)、Question 问题模块