https://github.com/liyinchigithub/Omysql
如果你电脑已经安装配置 Git、node 环境,可以直接按下面
步骤进行操作:
git clone git@github.com:liyinchigithub/express-mysql-restfulAPI.git
cd Omysql
npm install
node server.js
下面两个链接:
windows https://jingyan.baidu.com/article/1876c8529c79e2890b1376dd.html
mac https://jingyan.baidu.com/article/6b1823098bdd9fba59e1597a.html
在 postman 上面构建以下请求,即可实现 postman 访问数据库!
请求方法:POST 请求地址: http://127.0.0.1:8004/mysql_demo/CreateDB/ 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "query":"CREATE DATABASE Express_API_DB;" } 响应 body: { "result": "success", "status": 200 }
请求方法:POST 请求地址: http://127.0.0.1:8004/mysql_demo/CreateTable/ 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "query":"CREATE TABLE table4(name VARCHAR(100),id VARCHAR(100),age INT,address VARCHAR(100),tel INT,PRIMARY KEY ( id ))ENGINE=InnoDB DEFAULT CHARSET=utf8;" } 响应 body: { "result": "success", "status": 200 }
请求方法:PUT 请求地址: http://127.0.0.1:8004/mysql_demo/insert_data/ 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "addSql":"INSERT INTO table4(address,age,id,name,tel) VALUES(‘福建省泉州市丰泽区‘,19,225,‘刘丽丽‘,‘159115‘);" }
请求方法:PUT 请求地址:http://127.0.0.1:8004/mysql_demo/update/ 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "UpdateSql":"UPDATE table4 SET address=‘福建省厦门市 ‘,age=‘17‘,id=‘123‘,name=‘赵柳‘,tel=‘123123‘ WHERE name=‘刘丽丽 ‘;" }
请求方法:DELETE 请求地址:http://127.0.0.1:8004/mysql_demo/delete/ 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "delSql":"DELETE FROM table4 where name=‘王老五‘;" }
请求方法:DELETE 请求地址:http://127.0.0.1:8004/mysql_demo/drop 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "DropSql":"DROP TABLE table4;" }
请求方法:DELETE 请求地址:http://127.0.0.1:8004/mysql_demo/drop 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "DropSql":"DROP DATABASE Express_API_DB;" }
请求方法:POST 请求地址:http://127.0.0.1:8004/mysql_demo/find 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "findSql":"SELECT * FROM table4 WHERE name=‘赵柳‘;" }
请求方法:POST 请求地址:http://127.0.0.1:8004/mysql_demo/find 请求 body: { "host":"127.0.0.1", "user":"root", "password":"12345678", "port":"3306", "database":"数据库名称", "findSql":"SELECT * FROM table4;" }
请求方法:POST 请求地址: http://127.0.0.1:8004/mysql_demo/show_databases 请求 body: { "host":"127.0.0.1", "port":"3306", "user":"root", "password":"12345678", "findSql":"show databases" }
请求方法:POST 请求地址: http://127.0.0.1:8004/mysql_demo/show_databases 请求 body: { "host":"127.0.0.1", "port":"3306", "user":"root", "password":"12345678", "database":"数据库名称", "findSql":"show tables" }
本文作者:李静怡
原文:https://www.cnblogs.com/longronglang/p/11324456.html