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

2022-04-15 0 796

github地址https://github.com/dmhsq/dmhsq-mysql-db
可用于腾讯云SCF以及云开发环境
错误处理尚未完善 错误参考mysql错误
引入依赖包 npm install dmhsq-mysql-db
效果如下
简化了mysql的使用

nodejs环境快速操作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数据库内容请搜索NICE源码以前的文章或继续浏览下面的相关文章希望大家以后多多支持NICE源码!

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 JavaScript nodejs环境快速操作mysql数据库的方法详解 https://www.niceym.com/32404.html