techfort / LokiJS

javascript embeddable / in-memory database
http:/techfort.github.io/LokiJS
MIT License
6.73k stars 482 forks source link

LokiFSStructuredAdapter autosave not working #883

Closed StudentESE closed 2 years ago

StudentESE commented 3 years ago

@Mika83AC

const loki = require('lokijs');
const path = require('path');
const LokiFSStructuredAdapter = require('lokijs/src/loki-fs-structured-adapter');

let dbFile = path.resolve(__dirname, './test-data.json');

let Db = new loki(dbFile, 
  { 
    verbose: true,
    autosave: true, 
    // autoload: true,
    autosaveInterval: 1000,
    adapter: new LokiFSStructuredAdapter(),
    // autoloadCallback: databaseInitialize,
    autosaveCallback: () => { 
      console.log('autosaved db'); 
    }
  }
);

loadDb(({Db, test})=> {
  console.log('db loaded', Db);
  console.log('entries in db collection test', test.find());
});

console.log(Db); shows autosave: false

persistenceMethod: 'adapter',
  persistenceAdapter: LokiFsStructuredAdapter {
    mode: 'reference',
    dbref: {
      filename: 'db.json',
      collections: [Array],
      databaseVersion: 1.5,
      engineVersion: 1.5,
      autosave: false,
      autosaveInterval: 5000,
      autosaveHandle: null,
      throttledSaves: true,
      options: [Object],
      persistenceAdapter: null,
      verbose: false,
      events: [Object],
      ENV: 'NA'
    },

How do I get it enabled ? is there a path I can change the value of options (switching autosave on/off) while running? like ... db.persistenceAdaper['LokiFsStructuredAdapter'].dbref['autosave] = true; also manually save the collection doesn't trigger the autosaveCallback ... but showing the content of the memory db says it gots new entries.

I like to autosave to json. Please help :-)

Originally posted by @StudentESE in https://github.com/techfort/LokiJS/issues/563#issuecomment-818819120

GabCores commented 3 years ago

Hi there , I am doing some testing to get this library into a project, have you received some answer for this issue or got some workaround by yourself ? Thanks !

StudentESE commented 3 years ago

no, seams like there is no further support for this project.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.