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

DHCP Configuration Tutorial in CentOS7 Environment

Table of contents Configuration command steps in ...

Detailed explanation of fetch network request encapsulation example

export default ({ url, method = 'GET', da...

404 error occurs when accessing the homepage of tomcat started in Docker mode

Scenario: When starting tomcat in docker (version...

Summary of some HTML code writing style suggestions

Omit the protocol of the resource file It is reco...

XHTML tutorial, a brief introduction to the basics of XHTML

<br />This article will briefly introduce yo...

Docker sets up port mapping, but cannot access the solution

#docker ps check, all ports are mapped CONTAINER ...

How to install Android x86 in vmware virtual machine

Sometimes you just want to test an app but don’t ...

How to upload and download files between Linux server and Windows system

Background: Linux server file upload and download...

Analysis of MySQL multi-table joint query operation examples

This article describes the MySQL multi-table join...

Detailed explanation of client configuration for vue3+electron12+dll development

Table of contents Modify the repository source st...

Detailed explanation of HTML page header code example

Knowledge point 1: Set the base URL of the web pa...

Detailed explanation of count(), group by, order by in MySQL

I recently encountered a problem when doing IM, a...

React mouse multi-selection function configuration method

Generally, lists have selection functions, and si...

MySQL multi-table join introductory tutorial

Connections can be used to query, update, and est...

Detailed explanation of key uniqueness of v-for in Vue

Table of contents 1. DOM Diff 2. Add key attribut...