nodejs环境快速操作mysql数据库的方法详解
作者:代码哈士奇
这篇文章主要介绍了nodejs环境快速操作mysql数据库的方法详解,需要的朋友可以参考下
github地址https://github.com/dmhsq/dmhsq-mysql-db
可用于腾讯云SCF以及云开发环境
错误处理尚未完善 错误参考mysql错误
引入依赖包 npm install dmhsq-mysql-db
效果如下
简化了mysql的使用
安装依赖
npm install dmhsq-mysql-db
使用示例
快速操作mysql 错误处理尚未完善 部分错误参考mysql错误
引入资源
const database = require("dmhsq-mysql-db")
连接数据库
let db = new database({ host: 'xxx', port: 'xxx', user: 'xxxx', password: 'xxxx', database: "xxxx" })
引用表
let collection = db.table("user")
查询全部
collection.get().then(res => { console.log(res) })
条件查询
collection.where({ username: "dmhsq" }).get().then(res => { console.log(res) })
插入数据
collection.add({ username: "dmhsq", password: "dmhsq", _id: 123176312 }).then(res => { console.log(res) })
更新数据
collection.updata({ password: "zccc" }).where({ username: "dmhsq" }).then(res=>{ console.log(res) })
删除数据
collection.del().where({ username: "dmhsq" }).then(res => { console.log(res) })
到此这篇关于nodejs环境快速操作mysql数据库的方法详解的文章就介绍到这了,更多相关nodejs操作mysql数据库内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
- nodejs的错误处理过程记录
- Nodejs实现定时爬虫的完整实例
- NodeJS和浏览器中this关键字的不同之处
- nodejs处理tcp连接的核心流程
- Nodejs 数组的队列以及forEach的应用详解
- 一文秒懂nodejs中的异步编程
- 在nodejs中创建child process的方法
- nodejs中使用worker_threads来创建新的线程的方法
- Nodejs 微信小程序消息推送的实现
- Nodejs实现微信分账的示例代码
- nodejs中的异步编程知识点详解
- nodejs+express最简易的连接数据库的方法
- windows如何把已安装的nodejs高版本降级为低版本(图文教程)
- NodeJS配置CORS实现过程详解
- 如何利用nodejs自动定时发送邮件提醒(超实用)
- nodeJs项目在阿里云的简单部署
- 如何利用nodejs实现命令行游戏
- 搞懂什么是Node.js原来这么简单