typicode / lowdb

Simple and fast JSON database
MIT License
21.56k stars 924 forks source link

electron no read data #599

Open Hiram-Wong opened 2 months ago

Hiram-Wong commented 2 months ago
import _ from 'lodash';
import { Low } from 'lowdb';
import { JSONFileSync } from 'lowdb/node';
const STORE_PATH = join(app.getPath('userData'), 'database.json');
let defaultData = {
    tbl_setting: []
};
class LowWithLodash extends Low {
  chain = _.chain(this).get('data');
};
const adapter = new JSONFile(STORE_PATH);
const db = new LowWithLodash(adapter, defaultData);
console.log(db.chain.get('tbl_setting').castArray().value())

join(app.getPath('userData'), 'database.json') is have data,butJSONFileSyncread is undefine, uesfs.readFileSync(STORE_PATH, 'utf8') || {};can read it but not write,how to fix it

env: electron22 lowdb7.0.1