Skip to content

Commit

Permalink
Fix for table, articles, does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoung committed Jul 31, 2012
1 parent 0bd5d6a commit bc5f3d5
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions dataLoader/loader.js
Expand Up @@ -8,11 +8,21 @@ var newdb = '../assets/db/content.db3';
var childProcess = require('child_process');

// refresh
if(fs.existsSync(newdb))
childProcess.exec('rm ' + newdb);
if(fs.existsSync(newdb)) {
childProcess.exec('rm ' + newdb, copyBaseLine);
}
else {
copyBaseLine();
}

function copyBaseLine(err, stdout, stderr) {
if(err) {
console.log(err);
}

// clone db file
childProcess.exec('cp ' + baselinedb + ' ' + newdb, loadDocuments);
// clone db file
childProcess.exec('cp ' + baselinedb + ' ' + newdb, loadDocuments);
}

function loadDocuments(err) {
if(err) {
Expand All @@ -27,12 +37,21 @@ function loadDocuments(err) {
if(file === '.DS_Store')
return;

console.log('Processing: ' + file);

var doc = require(docPath + '/' + file);
db.run("insert into articles (number, title, text) values (?, ?, ?);",
doc.article, doc.title, doc.text);
doc.article, doc.title, doc.text, ran(file));
});

db.close();
}
}

function ran(file) {
return function(err) {
console.log('Processing: ' + file);

if(err) {
console.log(err);
return;
}
}
}

0 comments on commit bc5f3d5

Please sign in to comment.