当前位置:主页 > 查看内容

nodejs环境快速操作mysql数据库的方法详解

发布时间:2021-09-11 00:00| 位朋友查看

简介:github地址https://github.com/dmhsq/dmhsq-mysql-db 可用于腾讯云SCF以及云开发环境 错误处理尚未完善 错误参考mysql错误 引入依赖包 npm install dmhsq-mysql-db 效果如下 简化了mysql的使用 安装依赖 npm install dmhsq-mysql-db 使用示例 快速操作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数据库内容请搜索站长技术以前的文章或继续浏览下面的相关文章希望大家以后多多支持站长技术!


原文链接:https://m.jb51.net/article/208014.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:vue实现密码显示隐藏功能的思路详解 下一篇:没有了

推荐图文


随机推荐