Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update record followed by delete record without save leaves data behind #161

Open
damien-murphy opened this issue Jan 16, 2019 · 1 comment

Comments

@damien-murphy
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/LokiJS-Forge/LokiDB/blob/master/CONTRIBUTING.md#question

Current behavior

update a record
delete that record
save database
values left in database

Expected behavior

no values left in database

Minimal reproduction of the problem with instructions

save after (update record and delete record) leaves behind values in DB
save after update, save after delete record does not leave behind values

What is the motivation / use case for changing the behavior?

Explicitly saving database after an update and delete would leave behind records

Environment


LokiDB version: 2.0.0-beta.8

Browser/Node version: Chrome 71
@Viatorus
Copy link
Member

Sorry for the really late reply. I tried to reproduce the bug, but it didn't work:

const db = new Loki("myTestApp3");

db.initializePersistence()
  .then(() => {
    const coll = db.addCollection<Name>("myColl");
    // Insert documents.
    coll.insert({name: "Hello"});
    coll.insert({name: "World"});
    return db.saveDatabase(); // save or not save, doesn't changes anything
  }).then(() => {
  // Update and remove one record.
  const coll = db.getCollection<Name>("myColl");
  const doc = coll.find()[0];
  expect(doc.name == "Hello")
  doc.name = "Good by";
  coll.update(doc);
  coll.remove(doc);
  return db.saveDatabase();
})
  .then(() => {
    const all = db.getCollection<Name>("myColl").find();
    expect(all.length).toEqual(1);
    expect(all[0].name).toEqual("World");
  })
  .then(() => {
    // Load database.
    const db2 = new Loki("myTestApp2");
    return db2.initializePersistence({autoload: true})
      .then(() => {
        // Only one record present.
        const all = db.getCollection<Name>("myColl").find();
        expect(all.length).toEqual(1);
        expect(all[0].name).toEqual("World");
      });
  })
  .catch(e => {
    fail(e);
  })
  .then(() => {
    done();
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants