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

Free tool to verify that HTML, CSS and RSS feeds are correct

One trick for dealing with this type of error is t...

How are spaces represented in HTML (what do they mean)?

In web development, you often encounter characters...

Using streaming queries in MySQL to avoid data OOM

Table of contents 1. Introduction 2. JDBC impleme...

Install Percona Server+MySQL on CentOS 7

1. Environmental Description (1) CentOS-7-x86_64,...

A brief discussion on the solution of Tomcat garbled code and port occupation

Tomcat server is a free and open source Web appli...

CentOS7 installation zabbix 4.0 tutorial (illustration and text)

Disable SeLinux setenforce 0 Permanently closed: ...

18 Amazing Connections Between Interaction Design and Psychology

Designers need to understand psychology reading n...

Using front-end HTML+CSS+JS to develop a simple TODOLIST function (notepad)

Table of contents 1. Brief Introduction 2. Run sc...

Detailed example of using useState in react

useState useState adds some internal state to a c...

Vue-cli creates a project and analyzes the project structure

Table of contents 1. Enter a directory and create...

You really need to understand the use of CSS variables var()

When a web project gets bigger and bigger, its CS...

A brief talk about JavaScript variable promotion

Table of contents Preface 1. What variables are p...

A brief discussion on CSS height collapse problem

Performance For example: HTML: <div class=&quo...

Install docker offline by downloading rpm and related dependencies using yum

You can use yum to install all dependencies toget...