How does node.js operate the database efficiently

wzj5cnaz 2021-10-14 07:22:12

Simple Chinese
access-db file

Unify the connection of various databases

At present, there are :

database explain Supported version
FastDB Local json File database
[ from access_db Team development ] 0.0.6
MongoDB Distributed file storage database 4.x
Mysql Relational database 8.x, 5.x
redis High performance key-value database 6.x, 5.x
install
npm install access-db
yarn add access-db

Create a new directory at the project root .env file , Then fill in the configuration information
yarn add dotenv
Then at the beginning of the project , Introduce as early as possible require('dotenv').config()
.env The configuration is as follows

MYSQL_HOST MONGODB_HOST REDIS_HOST FASTDB_DIR What database do you use , Then the corresponding address is required , Do not fill in if it is not used

MYSQL_HOST=localhost // Not required , If it is not filled in, it means that the database is not used
MYSQL_USER=root
MYSQL_PASSWORD=123456
MYSQL_PORT=3306
MYSQL_DATABASE=
# Default UTF8_GENERAL_CI
# MYSQL_CHARSET=
# maximum connection , Default 10
# MYSQL_CONNECTION_LIMIT=

MONGODB_HOST=localhost // Not required , If it is not filled in, it means that the database is not used
MONGODB_USER=
MONGODB_PASSWORD=
MONGODB_DATABASE=
MONGODB_PORT=

REDIS_HOST=localhost // Not required , If it is not filled in, it means that the database is not used
REDIS_PORT=

FASTDB_DIR= // fastdb Data storage directory , Under the default project root directory fastdb Catalog

Use :
import {mysql, mongodb} from 'access-db'

async function exp() {
let {data} = await mongodb.get('tableName1', id)
await mysql.find('tableName2', {

p0: ['num', '=', data.num],
r: 'p0'

})
}

Please bring the original link to reprint ,thank
Similar articles