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)
})
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。