1. 程式人生 > 程式設計 >nodejs環境快速操作mysql資料庫的方法詳解

nodejs環境快速操作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-mysq程式設計客棧l-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 => {
	conhDKTasole.log(res)
})

插入資料

collection.add({
	username: "dmhsq",password: "dmhsq",_id: 123176312
}).then(res => {
	console.log(res)
})

更新資料

collection.updata({
	password: www.cppcns.com"zccc"
}).where({
	username: "dmhsq"
}).then(res=>{
	console.log(res)
})

刪除資料

collection.del().where({
	username: "dmhsq"
}).then(res => {
	console.log(res)
})

到此這篇關於nodejs環境快速操作mysql資料庫的方法詳解的文章就介紹到這了,更多相關nodejs操作mysql資料庫內容請搜尋我們程式設計客棧以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!