You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{join}from'path'import{Low,JSONFile}from'lowdb'// Use JSON file for storageconstfile=join(__dirname,'db.json')constadapter=newJSONFile(file)constdb=newLow(adapter)// Read data from JSON file, this will set db.data contentawaitdb.read()// If file.json doesn't exist, db.data will be null// Set default datadb.data||={posts: []}// Create and query items using plain JSdb.data.posts.push('hello world')db.data.posts[0]// You can also use this syntax if you preferconst{ posts }=db.dataposts.push('hello world')// Write db.data content to db.jsonawaitdb.write()
The text was updated successfully, but these errors were encountered:
背景
最近给 appworks/tooltik 写 pr 顺便学一下怎么写 electron,发现官方并没有提供数据缓存的方案,就是大家自由发挥。
方案
lowdb.js
下面要说的 lowdb.js 是 一个基于 JSON 的非关系型数据库。它提供了一些很简单的 CURD 功能,只需要传入你希望存放的文件路径。与其说它是数据库,我更觉得它是一个提供类数据库操作方法的 file system。而且它在大部分情况下,不提供兜底能力,例如在 electron 打包安装后,在新环境里没有db文件,需要自己手动创建db文件。
The text was updated successfully, but these errors were encountered: