github地址https://github.com/dmhsq/dmhsq-mysql-db
可用于騰訊云SCF以及云開發環境
錯誤處理尚未完善 錯誤參考mysql錯誤
引入依賴包 npm install dmhsq-mysql-db
效果如下
簡化了mysql的使用
安裝依賴
1
|
npm install dmhsq-mysql-db |
使用示例
快速操作mysql 錯誤處理尚未完善 部分錯誤參考mysql錯誤
引入資源
1
|
const database = require( "dmhsq-mysql-db" ) |
連接數據庫
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") |
查詢全部
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) }) |
插入數據
1
2
3
4
5
6
7
|
collection.add({ username: "dmhsq", password: "dmhsq", _id: 123176312 }).then(res => { console.log(res) }) |
更新數據
1
2
3
4
5
6
7
|
collection.updata({ password: "zccc" }).where({ username: "dmhsq" }).then(res=>{ console.log(res) }) |
刪除數據
1
2
3
4
5
|
collection.del().where({ username: "dmhsq" }).then(res => { console.log(res) }) |
到此這篇關于nodejs環境快速操作mysql數據庫的方法詳解的文章就介紹到這了,更多相關nodejs操作mysql數據庫內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/qq_42027681/article/details/115038010