nodejs環(huán)境快速操作mysql數(shù)據(jù)庫的方法詳解
github地址https://github.com/dmhsq/dmhsq-mysql-db
可用于騰訊云SCF以及云開發(fā)環(huán)境
錯誤處理尚未完善 錯誤參考mysql錯誤
引入依賴包 npm install dmhsq-mysql-db
效果如下
簡化了mysql的使用
安裝依賴
npm install dmhsq-mysql-db
使用示例
快速操作mysql 錯誤處理尚未完善 部分錯誤參考mysql錯誤
引入資源
const database = require("dmhsq-mysql-db")
連接數(shù)據(jù)庫
let db = new database({ host: 'xxx', port: 'xxx', user: 'xxxx', password: 'xxxx', database: "xxxx" })
引用表
let collection = db.table("user")
查詢?nèi)?/p>
collection.get().then(res => { console.log(res) })
條件查詢
collection.where({ username: "dmhsq" }).get().then(res => { console.log(res) })
插入數(shù)據(jù)
collection.add({ username: "dmhsq", password: "dmhsq", _id: 123176312 }).then(res => { console.log(res) })
更新數(shù)據(jù)
collection.updata({ password: "zccc" }).where({ username: "dmhsq" }).then(res=>{ console.log(res) })
刪除數(shù)據(jù)
collection.del().where({ username: "dmhsq" }).then(res => { console.log(res) })
到此這篇關(guān)于nodejs環(huán)境快速操作mysql數(shù)據(jù)庫的方法詳解的文章就介紹到這了,更多相關(guān)nodejs操作mysql數(shù)據(jù)庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Node.js中MongoDB查詢數(shù)據(jù)的方法
在Node.js中,可以使用MongoDB驅(qū)動程序和Mongoose庫來進行MongoDB的查詢操作,本文就來介紹一下Node.js中MongoDB查詢數(shù)據(jù)的方法,感興趣的可以了解一下2023-12-12nodejs實現(xiàn)HTTPS發(fā)起POST請求
這篇文章主要介紹了nodejs實現(xiàn)HTTPS發(fā)起POST請求的實例代碼,非常的簡單實用,有需要的小伙伴可以參考下。2015-04-04使用Phantomjs和Node完成網(wǎng)頁的截屏快照的方法
這篇文章主要介紹了使用Phantomjs和Node完成網(wǎng)頁的截屏快照的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07Node.js 使用 Express-Jwt和JsonWebToken 進行Token身份
這篇文章主要介紹了Node.js 使用 Express-Jwt和JsonWebToken 進行Token身份驗證的操作方法,本文通過實例代碼給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧2024-08-08