第五節(jié):Electron操作nedb數(shù)據(jù)庫(kù)

1.electron應(yīng)用操作數(shù)據(jù)的幾種方法:

1、遠(yuǎn)程api接口 (多個(gè)客戶(hù)端公用一套數(shù)據(jù))
2、連接遠(yuǎn)程數(shù)據(jù)庫(kù) (局域網(wǎng)內(nèi)使用 多個(gè)客戶(hù)端公用一套數(shù)據(jù) ) (不建議使用)
3、連接本地?cái)?shù)據(jù)庫(kù) (nedb sqlite) 應(yīng)用本地保存數(shù)據(jù)(localstore 5M) 用戶(hù)設(shè)置信息 qq聊天記錄

2.electron-vue讀寫(xiě)本地?cái)?shù)據(jù)庫(kù)文件

https://simulatedgreg.gitbooks.io/electron-vue/content/cn/savingreading-local-files.html

3.electron app模塊詳細(xì):

https://www.w3cschool.cn/electronmanual/electronmanual-electronapp.html

4.Nedb 數(shù)據(jù)庫(kù)文檔:

https://github.com/louischatriot/nedb
nedb數(shù)據(jù)庫(kù)和mongodb數(shù)據(jù)庫(kù)的操作方法幾乎一模一樣。
如果對(duì)mongodb數(shù)據(jù)庫(kù)不熟悉 請(qǐng)看以下教程:
https://www.itying.com/goods-783.html
koa教程封裝一個(gè)mongodb數(shù)據(jù)庫(kù)

5.electron-vue中使用Nedb 數(shù)據(jù)庫(kù)

(1)安裝nedb數(shù)據(jù)庫(kù)

cnpm install nedb --save

(2)新建一個(gè)src/renderer/datastore.js

import Datastore from 'nedb'
import path from 'path'
import { remote } from 'electron'
export default new Datastore({
  autoload: true,
  filename: path.join(remote.app.getPath('userData'), '/data.db')
})

(3)src/renderer/main.js

import db from './datastore.js'
/* 其它代碼 */
Vue.prototype.$db = db

(4)在vue的組件里面實(shí)現(xiàn)數(shù)據(jù)的增加 修改 刪除 顯示

this.$db.insert({},function(){
            
})
this.$db.find({},function(){
    //獲取查詢(xún)的數(shù)據(jù)
})

this.$db.update({條件},{$set:{更改的數(shù)據(jù)}},function(){
            
})

this.$db.remove({條件},{},function(){
            
})      
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容