Detailed explanation of how to quickly operate MySQL database in nodejs environment

Detailed explanation of how to quickly operate MySQL database in nodejs environment

GitHub address: https://github.com/dmhsq/dmhsq-mysql-db
Can be used in Tencent Cloud SCF and cloud development environment Error handling is not yet complete Error reference mysql error Introduce dependency package npm install dmhsq-mysql-db
The effect is as follows: Simplifies the use of MySQL

insert image description here

Install Dependencies

npm install dmhsq-mysql-db

Usage Examples

Quick operation mysql error handling is not yet perfect. For some errors, refer to mysql error

Introducing resources

const database = require("dmhsq-mysql-db")

Connecting to a database

let db = new database({
	host: 'xxx',
	port: 'xxx',
	user: 'xxxx',
	password: 'xxxx',
	database: "xxxx"
})

Reference table

let collection = db.table("user")

Search all

collection.get().then(res => {
	console.log(res)
})

Conditional Query

collection.where({
	username: "dmhsq"
}).get().then(res => {
	console.log(res)
})

Inserting Data

collection.add({
	username: "dmhsq",
	password: "dmhsq",
	_id: 123176312
}).then(res => {
	console.log(res)
})

Update data

collection.updata({
	password: "zccc"
}).where({
	username: "dmhsq"
}).then(res=>{
	console.log(res)
})

Deleting Data

collection.del().where({
	username: "dmhsq"
}).then(res => {
	console.log(res)
})

This concludes this article on how to quickly operate the MySQL database in a nodejs environment. For more information about how to operate the MySQL database in a nodejs environment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Nodejs error handling process record
  • A complete example of implementing a timed crawler with Nodejs
  • Differences between this keyword in NodeJS and browsers
  • The core process of nodejs processing tcp connection
  • Detailed explanation of Nodejs array queue and forEach application
  • Learn asynchronous programming in nodejs in one article
  • How to create a child process in nodejs
  • How to use worker_threads to create new threads in nodejs
  • Implementation of WeChat applet message push in Nodejs
  • Example code for implementing WeChat account splitting with Nodejs
  • Detailed explanation of asynchronous programming knowledge points in nodejs
  • The simplest way to connect to the database with nodejs+express
  • How to downgrade the installed nodejs high version to a lower version in windows (graphic tutorial)
  • Detailed explanation of the implementation process of NodeJS CORS configuration
  • How to use nodejs to automatically send email reminders at regular intervals (super practical)
  • Simple deployment of nodeJs project in Alibaba Cloud
  • How to use nodejs to implement command line games
  • Understanding what Node.js is is so easy

<<:  Linux kernel device driver proc file system notes

>>:  How to enable slow query log in MySQL

Recommend

mysql5.7.20 installation and configuration method graphic tutorial (mac)

MySQL 5.7.20 installation and configuration metho...

How to delete a MySQL table

It is very easy to delete a table in MySQL, but y...

Summary of the data storage structure of the nginx http module

Starting from this section, we will explain the i...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

Centos8 bridge static IP configuration method in VMware virtual machine

1. Make sure the network connection method is bri...

How to solve jQuery conflict problem

In front-end development, $ is a function in jQue...

JS implements request dispatcher

Table of contents Abstraction and reuse Serial Se...

A brief description of the relationship between k8s and Docker

Recently, the project uses kubernetes (hereinafte...

KVM virtualization installation, deployment and management tutorial

Table of contents 1.kvm deployment 1.1 kvm instal...

Zen Coding Easy and fast HTML writing

Zen Coding It is a text editor plugin. In a text ...

Vue realizes web online chat function

This article example shares the specific code of ...

How to implement a simple HTML video player

This article introduces the method of implementin...

Teach you to create custom hooks in react

1. What are custom hooks Logic reuse Simply put, ...

Solution to the inaccessibility of Tencent Cloud Server Tomcat port

I recently configured a server using Tencent Clou...