当前位置:网站首页>Node connects to MySQL database and writes fuzzy query interface
Node connects to MySQL database and writes fuzzy query interface
2022-06-11 11:30:00 【Yanyan is very WOW!】
One 、 preparation
1. install mysql
2.node Install database in
// node Install in mysql
npm install mysql
3.node Connect to database
(1) stay db New file in directory sql.js
// sql.js
var mysql = require('mysql') // introduce
var connection = mysql.createConnection({
host: 'localhost', // Host name
user: 'root', // account number
password: 'root', // password
database: 'mysql', // The name of the library to be connected
})
module.exports = connection
(2) stay MySQL Create tables in the database 
Two 、 Write the interface
// stay routes Under folder index.js Write the following interfaces in
var express = require('express')
var router = express.Router()
var connection = require('../db/sql.js') // Bring in the connected database
router.get('/api/goods/search', function (req, res, next) {
// Interface
let [goodsName, orderName] = Object.keys(req.query) // Parameters obtained from the front end
console.log(goodsName, orderName)
let name = req.query.name
let order = req.query[orderName]
connection.query(
"select * from goods_search where name like '%" +
// Here is the fuzzy query , By name or discount perhaps oprice Fuzzy query
name +
"%' order by " +
orderName +
' ' +
order +
'',
function (error, result, fields) {
// if (error) throw error
res.send({
code: '0',
data: result,
})
}
)
})
module.exports = router
3、 ... and 、 The test results
// By name “ Big ” and discount Field fuzzy query , among asc In ascending order ,desc For the descending order 
// By name “ Small ” and discount Field fuzzy query 
边栏推荐
- JS prototype. The find () method has no effect on the object array. It is urgent...
- 灵动边栏(Widget)插件:MO Widgets
- WP super cache static cache plug-in concise tutorial
- Use yolov3 to train yourself to make datasets and get started quickly
- WordPress landing page customization plug-in recommendation
- Method of converting VOC format data set to Yolo format data set
- 在WordPress媒体库中创建文件夹
- [C language] anonymous/unnamed struct & Union
- 数据库系统概论 ---- 第二章 -- 关系数据库(2.4 关系代数)
- Use pydub to modify the bit rate of the wav file, and an error is reported: c:\programdata\anaconda3\lib\site packages\pydub\utils py:170: RuntimeWarning:
猜你喜欢

Characteristics and classification of creation mode (single case, factory)

MySQL optimized learning diary 10 - locking mechanism

National multi-year solar radiation spatial distribution data 1981-2022, temperature distribution data, evapotranspiration data, evaporation data, rainfall distribution data, sunshine data, wind speed
![Set the default receiving address [project mall]](/img/eb/2864b124b66d01849315a367948ed4.png)
Set the default receiving address [project mall]

JS interview questions - arrow function, find and filter some and every
![my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题](/img/bd/a28e74654c7821b3a9cd9260d2e399.png)
my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题

全国多年太阳辐射空间分布数据1981-2022年、气温分布数据、蒸散量数据、蒸发量数据、降雨量分布数据、日照数据、风速数据

Exploration of kangaroo cloud data stack on spark SQL optimization based on CBO

An introduction to creating VOC datasets or Yolo datasets using labelimg

收货地址列表展示【项目 商城】
随机推荐
SpingBoot+Quartrz生产环境的应用支持分布式、自定义corn、反射执行多任务
WordPress登录页面美化插件:Login Designer推荐
推荐几款Gravatar头像缓存插件
National multi-year solar radiation spatial distribution data 1981-2022, temperature distribution data, evapotranspiration data, evaporation data, rainfall distribution data, sunshine data, wind speed
Surrounddepth: self supervised multi camera look around depth estimation
WP super cache static cache plug-in concise tutorial
Définir l'adresse de réception par défaut [Centre commercial du projet]
Processing of uci-har datasets
【碎碎念】关于波长|波速|周期的想法
Create a folder in the WordPress Library
Learning in Bi design 03
Application of volatile in single chip microcomputer
WordPress数据库缓存插件:DB Cache Reloaded
NFT digital collection system platform construction
WordPress landing page beautification plug-in: recommended by login Designer
让WordPress支持注册用户上传自定义头像功能
Vscade -- vscode multi window name is configured as project name
Droid-slam: depth vision slam for monocular and binocular rgbd cameras
Use yolov5 to train your own data set and get started quickly
Where is it safer to open an account for soda ash futures? How much capital is needed to trade soda ash futures at present?