antiboredom / servi.js

36 stars 6 forks source link

updating and removing records #5

Closed shiffman closed 9 years ago

shiffman commented 10 years ago

This fails:

var servi = require('servi');
var app = new servi(true);

var concordance = useDatabase("words");

var sampleData = {
  word: 'blah',
  count: 12
};
concordance.add(sampleData);
concordance.search('word', 'blah', searchDone);

function searchDone(data) {
  var record = data[0];
  console.log(record._id);

  // Can't get this to work
  // concordance.remove(record._id);

  // Can't get this to work
  // concordance.change(record._id, {count: 15});
}

The fix for now is:

concordance.remove({_id: record._id}, {});
concordance.update({_id: record._id}, {$set: {count: 15}}, {});
shiffman commented 10 years ago

Actually:

 concordance.db.update({_id: id}, {$set: {count: 15}}, {}); 
getarobo commented 9 years ago

Realized removing and updating doesn't change DB file directly. instead it make an record of deleted _id and new entry, instead of actually deleting line or updating entry.

I was loading DB file created by "useDatabase("words");" and parsing it into array of JSON. But I now I am getting all these duplicates and logs.

Is there way to directly access DB directly without sending post to server and server route()ing to to new page with template used?

I want direct access to DB.

antiboredom commented 9 years ago

@getarobo you can access the database directly in a few ways. First, you can simply open up and edit the database file. Second, you can bypass servi's methods and access the database object with yourdbname.db. You'll then have access to all the functions listed here: https://github.com/louischatriot/nedb

@shiffman I've fixed removing and updating so those should work now.