当前位置:网站首页>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–
边栏推荐
- [opencv learning] [common image convolution kernel]
- What are eNB, EPC and PGW?
- Principle analysis of security rememberme
- Explain in detail the process of realizing Chinese text classification by CNN
- Jerry's weather code table [chapter]
- Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
- Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
- Web Foundation
- Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
- Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
猜你喜欢

mac(macos Monterey12.2 m1) 个人使用php开发

Unity skframework framework (XXI), texture filter map resource filtering tool

基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】

Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)

自主可控三维云CAD:CrownCAD赋能企业创新设计
![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

Unity skframework framework (XV), singleton singleton

de4000h存储安装配置

Everyone wants to eat a broken buffet. It's almost cold

Unity skframework framework (XVII), freecameracontroller God view / free view camera control script
随机推荐
[opencv learning] [common image convolution kernel]
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
(6) Web security | penetration test | network security encryption and decryption ciphertext related features, with super encryption and decryption software
三面阿里,有惊无险成功拿到offer定级P7,只能说是真的难
Unity skframework framework (XIII), question module
Unity skframework framework (XVI), package manager development kit Manager
Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
文件的下载与图片的预览
Unity skframework framework (XIX), POI points of interest / information points
moon
每日一题:1175.质数排列
Unity SKFramework框架(十六)、Package Manager 开发工具包管理器
Mysql常用命令详细大全
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
Daily question: 1175 Prime permutation
Unity SKFramework框架(十九)、POI 兴趣点/信息点
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
能自动更新的万能周报模板,有手就会用!
Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud