nodejs環(huán)境快速操作mysql數(shù)據(jù)庫(kù)的方法詳解
github地址https://github.com/dmhsq/dmhsq-mysql-db
可用于騰訊云SCF以及云開發(fā)環(huán)境
錯(cuò)誤處理尚未完善 錯(cuò)誤參考mysql錯(cuò)誤
引入依賴包 npm install dmhsq-mysql-db
效果如下
簡(jiǎn)化了mysql的使用

安裝依賴
npm install dmhsq-mysql-db
使用示例
快速操作mysql 錯(cuò)誤處理尚未完善 部分錯(cuò)誤參考mysql錯(cuò)誤
引入資源
const database = require("dmhsq-mysql-db")
連接數(shù)據(jù)庫(kù)
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ù)庫(kù)的方法詳解的文章就介紹到這了,更多相關(guān)nodejs操作mysql數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Node.js中MongoDB查詢數(shù)據(jù)的方法
在Node.js中,可以使用MongoDB驅(qū)動(dòng)程序和Mongoose庫(kù)來(lái)進(jìn)行MongoDB的查詢操作,本文就來(lái)介紹一下Node.js中MongoDB查詢數(shù)據(jù)的方法,感興趣的可以了解一下2023-12-12
nodejs 生成和導(dǎo)出 word的實(shí)例代碼
前段時(shí)間由于項(xiàng)目需求,得做excel和word的導(dǎo)出功能.這篇文章主要介紹了nodejs 生成和導(dǎo)出 word的實(shí)例代碼,需要的朋友可以參考下2018-07-07
Node.js進(jìn)行文件操作(讀取/寫入/修改/刪除)詳解
Node.js是一個(gè)神奇的東西,它可以讓JavaScript在服務(wù)器端運(yùn)行,讓我們的很多前端程序員也能在后端大展身手了!本文就來(lái)講講如何在Node.js中進(jìn)行文件操作:讀取、寫入、修改和刪除文件吧2023-03-03
nodejs實(shí)現(xiàn)HTTPS發(fā)起POST請(qǐng)求
這篇文章主要介紹了nodejs實(shí)現(xiàn)HTTPS發(fā)起POST請(qǐng)求的實(shí)例代碼,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2015-04-04
使用Phantomjs和Node完成網(wǎng)頁(yè)的截屏快照的方法
這篇文章主要介紹了使用Phantomjs和Node完成網(wǎng)頁(yè)的截屏快照的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
Node.js 使用 Express-Jwt和JsonWebToken 進(jìn)行Token身份
這篇文章主要介紹了Node.js 使用 Express-Jwt和JsonWebToken 進(jìn)行Token身份驗(yàn)證的操作方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-08-08

