github地址https://github.com/dmhsq/dmhsq-mysql-db
可用于騰訊云SCF以及云開發(fā)環(huán)境
錯(cuò)誤處理尚未完善 錯(cuò)誤參考mysql錯(cuò)誤
引入依賴包 npm install dmhsq-mysql-db
效果如下
簡(jiǎn)化了mysql的使用
安裝依賴
1
|
npm install dmhsq-mysql-db |
使用示例
快速操作mysql 錯(cuò)誤處理尚未完善 部分錯(cuò)誤參考mysql錯(cuò)誤
引入資源
1
|
const database = require( "dmhsq-mysql-db" ) |
連接數(shù)據(jù)庫(kù)
1
2
3
4
5
6
7
|
let db = new database({ host: 'xxx' , port: 'xxx' , user: 'xxxx' , password: 'xxxx' , database: "xxxx" }) |
引用表
1
|
let collection = db.table("user") |
查詢?nèi)?/p>
1
2
3
|
collection.get().then(res => { console.log(res) }) |
條件查詢
1
2
3
4
5
|
collection.where({ username: "dmhsq" }).get().then(res => { console.log(res) }) |
插入數(shù)據(jù)
1
2
3
4
5
6
7
|
collection.add({ username: "dmhsq", password: "dmhsq", _id: 123176312 }).then(res => { console.log(res) }) |
更新數(shù)據(jù)
1
2
3
4
5
6
7
|
collection.updata({ password: "zccc" }).where({ username: "dmhsq" }).then(res=>{ console.log(res) }) |
刪除數(shù)據(jù)
1
2
3
4
5
|
collection.del().where({ username: "dmhsq" }).then(res => { console.log(res) }) |
到此這篇關(guān)于nodejs環(huán)境快速操作mysql數(shù)據(jù)庫(kù)的方法詳解的文章就介紹到這了,更多相關(guān)nodejs操作mysql數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/qq_42027681/article/details/115038010